2017-02-18 89 views
0

我正在學習,並且我自己目前無法弄清楚。AnyObject類型的值沒有成員生成器

我的代碼是:

func takeScreenshot(completionHandler handler: ((NSData!) -> Void)!) 
    { 
     // find out video connection 
     var videoConnection: AVCaptureConnection? 
     for conn in stillImageOutput!.connections { 
      for port in conn.inputPorts { 
       if port.mediaType == AVMediaTypeVideo { 
        videoConnection = conn as? AVCaptureConnection 
        break 
       } 
      } 
      if videoConnection != nil { 
       break 
      } 
     } 
     stillImageOutput!.captureStillImageAsynchronouslyFromConnection(videoConnection) { (sampleBuffer: CMSampleBuffer!, err: NSError!) in 
      let data = AVCaptureStillImageOutput.jpegStillImageNSDataRepresentation(sampleBuffer) 
      handler(data) 
     } 
    } 

在循環 「在conn.inputPorts端口」 我的錯誤。

感謝您的幫助!

+0

類型'AnyObject'沒有成員什麼?通常有一些事情要結束該聲明,以澄清你試圖操縱的東西不存在 – Pierce

+0

也許你的意思是做'connections.inputPorts'?...不知道,沒有足夠的信息。 –

+0

AnyObject類型的值在'Generator'中沒有成員 –

回答

0

你在兩個地方實際上有同樣的問題。首先是connections財產,它似乎是AVCaptureOutput類的財產。 connections被宣告爲NSArray

第二,類似的問題與您使用inputPortsinputPorts似乎是AVCaptureConnection類的一個屬性。 inputPorts被宣告爲NSArray

您遇到的問題是connportAnyObject類型結尾,因爲Swift不知道兩個數組中的對象是什麼類型。

因此,您嘗試訪問類型爲AnyObject的變量的屬性會導致錯誤。

您有兩種選擇。

  1. 角色的connections陣列的AVCaptureSessioninputPorts一個夫特陣列的AVCaptureInputPort一個夫特陣列。
  2. 鑄造connAVCaptureSessionportAVCaptureInputPort
+0

謝謝!有效! –

+0

很高興幫助。請不要忘記接受解決您的問題的答案。這讓人們知道你的問題已經解決了。 – rmaddy

相關問題