Reputation: 2207
I want to use a class I got from iosframeworks.com called UIImage+ProportionalFill
. I know it's a category extending UIImage
, but when I try to use one of its methods in another class I get a message saying no visible @interface for UIImage declares the selector 'nameOfWhateverMethodIWantToUse'
. I'm not surprised to get an error, since there must be more to using it than dropping it into XCode, but how do I make the methods in the new category/class available to other classes?
Upvotes: 1
Views: 146
Reputation: 627
Based on what you said, I think you just forgot to import it.
#import "UIImage+ProportionalFill.h"
Write it on the top of the .h file of the class where you want to use the method.
Upvotes: 2
Reputation: 162722
You need to #import
the header containing the method declaration(s) in each file that uses said methods.
Note tha the methos should be prefixed; i.e. -JDnameOfWhateverMethodIWantToUse
.
Note also that adding categories to framework classes willy nilly can easily lead to a rather awfully architected application that becomes difficult to refactor/maintain.
Upvotes: 2
Reputation: 64022
The compiler needs to be able to see the declaration of the methods, which should be in the category's header file. You must import the header file wherever you want to use the methods.
Upvotes: 2
Reputation: 15661
You just need to import your category in the class you like to use it...
#import "UIImage+ProportionalFill.h"
I usually do this in the header file.
Upvotes: 4