let stillImageConnection: AVCaptureConnection? = connectionWithMediaType(mediaType: .video, connections: (stillImageOutput?.connections)! as [AnyObject])
open func connectionWithMediaType(mediaType: AVMediaType, connections: [AnyObject]) -> AVCaptureConnection? {
for connection: AnyObject in connections {
let connectionTmp: AVCaptureConnection = connection as! AVCaptureConnection
for port: Any in connectionTmp.inputPorts {
if (port as AnyObject).isKind(of: AVCaptureInput.Port.self) {
let portTmp: AVCaptureInput.Port = port as! AVCaptureInput.Port
if portTmp.mediaType == mediaType {
return connectionTmp
}
}
}
}
return nil
}
能不能用guard和可选绑定代替强制解包? 能不能不要这么多无意义的强制转型?
先把[AVCaptureConnection]强制转成[AnyObject] 再遍历 强制转回 AVCaptureConnection 这是什么操作????
这代码这么多强制操作真的大丈夫???