2017-01-03 3 views
1

CIDetector 클래스를 사용하여 사각형을 감지하고 싶지만이 클래스의 인스턴스를 만들 수 없습니다.iOS Swift : CIDetectorTypeRectangle을 변환 할 수 없습니다.

private lazy var rectangleDetector: CIDetector? = { 
    let options: [String : AnyObject] = [ 
     CIDetectorAccuracy: CIDetectorAccuracyHigh, 
     CIDetectorMinFeatureSize: 0.5, 
     CIDetectorAspectRatio: 0.7 
    ] 

    return CIDetector(ofType: CIDetectorTypeRectangle, context: nil, options: options) 
}() 

내가 엑스 코드 8.2.1 및 스위프트 2.3을 사용 :이 코드를 사용

'(ofType: String, context: CIContext?, options: [String : AnyObject]?) -> CIDetector' is not convertible to '(ofType: String, context: CIContext?, options: [String : AnyObject]?) -> CIDetector?' 

: 나는 오류 메시지가 표시됩니다. Swift 2.2와 함께 XCode 7에서 사용했을 때 오류가 없었습니다. 아무도 여기서 무엇이 잘못되었는지를 압니까?

+0

Swift 2.3을 사용하고 있습니까? 아니면 Swift 3입니까? –

+0

예, 스위프트 2.3을 사용하고 "기존 스위프트 언어 버전 사용"을 YES로 설정했습니다. –

+0

나에게 Xcode 8 및 Swift 2.3에서 작동 중이므로 정리를 시도하십시오. 여전히 작동하지 않으면 코드를 추가하십시오 –

답변

1

반환 된 감지기가 현재 선택 사항 인 것 같습니다. 사용하기 전에 언 래핑 해보십시오.

guard let detector = CIDetector(ofType: CIDetectorTypeRectangle, context: nil, options: nil) else { 
    return //Or better yet throw error 
} 

//Do something with detector 
+0

시도했지만 도움이되지 않았습니다. –