I want to use CIDetector class to detect rectangles but I cannot create the instance of this class. I get the error message:
'(ofType: String, context: CIContext?, options: [String : AnyObject]?) -> CIDetector' is not convertible to '(ofType: String, context: CIContext?, options: [String : AnyObject]?) -> CIDetector?'
I use this code:
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)
}()
I use XCode 8.2.1 and Swift 2.3. There wasn't any error when I used it in XCode 7 with Swift 2.2. Does anybody know what is wrong here?
It looks like the returned detector is now optional. Try unwrapping it before using it.