2017-11-27 3 views
-1

나는이 코드를 가지고 있으며 노란색 경고를 던지고있다. 노란색 경고가 사라지도록 코드를 작성하는 방법을 알아낼 수 없습니다. > 3 - - 스위프트-2에서 변환 한 후 내 코드를 정리하려고> 4.'[AVCaptureDevice]'에서 '[AVCaptureDevice]'까지 조건부 캐스트가 항상 성공합니다. 노란색 경고

override func viewDidLoad() { 
     super.viewDidLoad() 
     // Do any additional setup after loading the view, typically from a nib. 

     //On iPad Mini this returns 760 x 1024 = correct 
     //On the iPhone SE, this returns 320x568 = correct 
     print("Width: \(screenWidth)") 
     print("Height: \(screenHeight)") 

     //======================= 

     captureSession.sessionPreset = AVCaptureSession.Preset.high 

     if #available(iOS 10.0, *) { 
      if let devices = AVCaptureDevice.default(AVCaptureDevice.DeviceType.builtInWideAngleCamera, for: AVMediaType.video, position: .back) { 

       print("Device name: \(devices.localizedName)") 

      } 
     } else { 

     } 

if let devices = AVCaptureDevice.devices() as? [AVCaptureDevice] { 
     // Loop through all the capture devices on this phone 
     for device in devices { 

      print("Device name: \(device.localizedName)") 

      // Make sure this particular device supports video 
      if (device.hasMediaType(AVMediaType.video)) { 
       // Finally check the position and confirm the back camera 
       if(device.position == AVCaptureDevice.Position.back) { 
        captureDevice = device 
        if captureDevice != nil { 
         print("Capture device found") 
         beginSession() 


       } 
      } 
     } 
    } 
    } 

} 
+0

제거 '는 단순히입니까? [AVCaptureDevice] ' – zombie

+0

빨간색 오류가 발생합니다 : 조건부 바인딩의 초기화 프로그램에는'[AVCaptureDevice] '가 아닌 Optional 유형이 있어야합니다. 이전에 시도했지만 그래도 계속합니다. 죄송합니다. –

+0

선택 품목이 아니므로 if 또는 점검이 필요한 이유 – zombie

답변

2

오류 메시지하면 조건부 중복 선택 유형이 아닌 옵션 타입 캐스팅 말한다.

선언 확인 devices

class func devices() -> [AVCaptureDevice]

을을 ⌥ 클릭 그래서

let devices = AVCaptureDevice.devices() 
// Loop through all the capture devices on this phone 
for device in devices { ... 
+0

고맙습니다. } ios10 테스트 바로 위에 문제가 없으면 else {...}를 다시 추가해야했습니다. 문제 없다. –

관련 문제