This code does compile perfectly fine
let ciImage = CIImage(image:UIImage())
however when I move it into an extension of UIImage
extension UIImage {
func foo() {
let ciImage = CIImage(image:UIImage()) // compile error
}
}
I get the following compile error
Cannot call value of non-function type 'CIImage?'
Why?
Tested with Xcode Playground 7.1.1. and Swift 2.1
It's because, once inside UIImage, the term CIImage
is seen as the CIImage
property of UIImage, due to implicit self
as message recipient — in other words, Swift turns your CIImage
into self.CIImage
and it's all downhill from there.
You can solve this by disambiguating thru Swift's use of module namespacing:
extension UIImage {
func foo() {
let ciImage = UIKit.CIImage(image:UIImage())
}
}
EDIT In Swift 3 this problem will go away, because all properties will start with small letters. The property will be named ciImage
, and there will be no confusion with the CIImage class.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With