我正在尝试将此代码转换为swift,但是在if语句中不断收到错误,objective-c代码如下所示:
AVCaptureStillImageOutput *stillImageOutPut;
AVCaptureConnection *videoConnection = nil;
for (AVCaptureConnection *connection in stillImageOutput.connections){
for (AVCaptureInputPort *port in [connection inputPorts]){
if ([[port mediaType] isEqual:AVMediaTypeVideo]){
videoConnection = connection;
break;
}
}
}
我的Swift代码如下所示:
let stillImageOutPut = AVCaptureStillImageOutput()
let videoConnection:AVCaptureConnection? = nil
for connection in stillImageOutPut.connections{
for port in [connection.inputPorts]{
if
}
}
在if语句中,我找不到,.mediaType
并且自动完成功能说description
,getMirror
和map
。我尝试过以其他方式在for循环中强制转换类型,但我总是不断出错。
关于如何正确创建此for循环的任何建议将不胜感激。
stillImageOutPut.connections
NSArray
在Objective-C中是一个,Array<AnyObject>
在Swift中是一个。您将需要Array<AVCaptureConnection>
在Swift中将其转换为。同样,您需要转换connection.inputPorts
为Array<AVCaptureInputPort>
。
let stillImageOutPut = AVCaptureStillImageOutput()
var videoConnection:AVCaptureConnection? = nil
for connection in stillImageOutPut.connections as [AVCaptureConnection] {
for port in connection.inputPorts as [AVCaptureInputPort] {
if port.mediaType == AVMediaTypeVideo {
videoConnection = connection
}
}
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句