1
我想使用CIDetector類來檢測矩形,但我無法創建此類的實例。我得到的錯誤信息:iOS Swift:CIDetectorTypeRectangle不可轉換
'(ofType: String, context: CIContext?, options: [String : AnyObject]?) -> CIDetector' is not convertible to '(ofType: String, context: CIContext?, options: [String : AnyObject]?) -> CIDetector?'
我用這個代碼:
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)
}()
我使用的XCode 8.2.1和SWIFT 2.3。當我在Swift 2.2的XCode 7中使用它時沒有任何錯誤。有人知道這裏有什麼問題嗎?
你確定你在使用Swift 2.3還是Swift 3? –
是的,我使用Swift 2.3,並將「使用傳統Swift語言版本」設置爲YES。 –
嘗試清理構建,因爲對我來說它使用Xcode 8和Swift 2.3或者如果仍然無效,請使用它添加更多的代碼 –