I'm trying to write my own CIFilter in Swift. I'm having problems when it comes to the real beef of the class, which is the outputImage
method:
class CustomFilter : CIFilter {
var kernel: CIKernel
var inputImage: CIImage
var color: CIColor
var threshold: NSNumber
// ... stuff omitted ...
func outputImage() -> CIImage {
let zero = NSNumber(double: 0 as Double)
let width = NSNumber(double: inputImage.extent().size.width.native as Double)
let height = NSNumber(double: inputImage.extent().size.height.native as Double)
let src = CISampler(image: inputImage)
let arguments = [src, color, threshold] as [AnyObject]
let extent = [zero, zero, width, height]
return self.apply(
kernel,
arguments: arguments,
options: (kCIApplyOptionExtent: extent)
)
}
}
The compiler error message concerning the last line of the method is as follows:
Cannot convert the expression's type '(@lvalue CIKernel, arguments: [AnyObject], options: (kCIApplyOptionExtent: [NSNumber]))' to type 'CIKernel!'
Can someone with more Swift or Core Image experience please point me in the right direction? I couldn't find an answer even after an hour of trying and googling...
Use square brackets to create the options dictionary:
return self.apply(kernel, arguments: arguments, options: [kCIApplyOptionExtent: extent])
The required argument is of type [NSObject : AnyObject]!