Reputation: 17677
I have a protocol in Objective-C, something like this:
@protocol Handler
+(NSString*) getValue;
@end
So now say I have an instance that inherits this protocol and I want to call this method:
[handlerInstance getValue];
This gives a warning because the getValue
method is not an instance method. How can I properly call this method from my instance? (Without knowing the concrete class)? I'm guessing something like this, but I'm not exactly sure:
[[handlerInstance class] getValue];
Upvotes: 22
Views: 12437
Reputation: 523164
[[handlerInstance class] getValue];
Yes, like this.
Unlike Java and C++, class methods can only be sent to the class.
Upvotes: 24