Swift 类型Any不符合协议序列

Swift 类型Any不符合协议序列,swift,xcode,protocols,sequence,Swift,Xcode,Protocols,Sequence,我在一个项目中使用Github项目,由于最近的Xcode 8.3更新,编译器抛出错误: /MMSCameraViewController/Classes/MMSCameraViewController.swift:448:42:键入“[任何]!!”不符合协议“顺序” for port in (connection as AnyObject).inputPorts { // <----- this line throws error if (port as! AVCaptureInpu

我在一个项目中使用Github项目,由于最近的Xcode 8.3更新,编译器抛出错误:

/MMSCameraViewController/Classes/MMSCameraViewController.swift:448:42:键入“[任何]!!”不符合协议“顺序”

for port in (connection as AnyObject).inputPorts { // <----- this line throws error
   if (port as! AVCaptureInputPort).mediaType == AVMediaTypeVideo {
       videoConnection = connection as! AVCaptureConnection
       break connectionloop
   }
}

中的端口(连接为AnyObject)。inputPorts{/因为AnyObject不是您想要的,所以错误非常明显

for port in (connection as! AVCaptureConnection).inputPorts {
     if (port as! AVCaptureInputPort).mediaType == AVMediaTypeVideo {
            videoConnection = connection as! AVCaptureConnection
            break connectionloop
     }
}

库应该遍历每个端口,这样任何对象都没有任何

我假设您的连接是AVCaptureConnection类,所以您不应该将其强制转换为任何对象:

// Change first line to this
for port in connection.inputPorts { 
   // Also to make it more secure (and avoid force casting)
   if let port = port as? AVCaptureInputPort, 
        port.mediaType == AVMediaTypeVideo {

       // You can delete force casting also here
       videoConnection = connection
       break connectionloop
   }
}