簡體   English   中英

類型Any不符合協議序列

[英]Type Any does not conform to protocol Sequence

我在一個項目中使用Github項目MMSCameraViewController ,由於最近的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
   }
}

我搜索了最近在這里出現的其他有關無序序列文章的文章,但是沒有一個對我有幫助(而且我是Swift的新人)。 任何想法如何解決這個問題?

非常感謝!

馬丁

因為AnyObject不是您想要的,所以錯誤很明顯。

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

庫應該通過每個端口,因此AnyObject沒有任何端口

我假設您的連接是AVCaptureConnection類,因此您不應將其強制轉換為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
   }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM