Reputation: 2861
I'm using the Github project MMSCameraViewController in a project and since the recent Xcode 8.3 update the compiler throws the error:
/MMSCameraViewController/Classes/MMSCameraViewController.swift:448:42: Type '[Any]!!' does not conform to protocol 'Sequence'
for port in (connection as AnyObject).inputPorts { // <----- this line throws error
if (port as! AVCaptureInputPort).mediaType == AVMediaTypeVideo {
videoConnection = connection as! AVCaptureConnection
break connectionloop
}
}
I've search the other posts about type-any-sequence posts appearing here recently, but none of that helped me (and I'm new to Swift). Any idea how to solve this?
Thanks a lot!
Martin
Upvotes: 1
Views: 4692
Reputation: 141
I assume that your connection is AVCaptureConnection class so you shouldn't cast it to AnyObject:
// 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
}
}
Upvotes: 1
Reputation: 2685
Because AnyObject is not what you want, error is really clear.
for port in (connection as! AVCaptureConnection).inputPorts {
if (port as! AVCaptureInputPort).mediaType == AVMediaTypeVideo {
videoConnection = connection as! AVCaptureConnection
break connectionloop
}
}
Library should go through every port so AnyObject does not have any
Upvotes: 1