Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot call value of non-function type 'CIImage?'

Tags:

swift

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

like image 203
Luca Angeletti Avatar asked Dec 05 '15 14:12

Luca Angeletti


1 Answers

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.

like image 107
matt Avatar answered Nov 12 '22 09:11

matt