I have this instance method in an existing Obj-C UIImage category:
- (UIImage *)applyDarkEffect;
I'm trying to call it from a Swift file like so:
self.backgroundImageView.image = UIImage.applyDarkEffect(image)
But get this compiler error:
Function produces expected type 'UIImage!'; did you mean to call it with '()'?
Best How To :
If you look at the method you have defined in Objective C image category, it is instance method and you are trying to call it using UIImage class in swift.
You can basically use either one of the following two approaches,
self.backgroundImageView.image = self.someImage.applyDarkEffect() // notice the method does not take argument
Or if you want to use class level method, then first create a closure and call it as,
let applyEffectToImageClosure = UIImage.applyDarkEffect(self.someImage)
self.backgroundImageView.image = applyEffectToImageClosure()