21
votes

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];
1

1 Answers

21
votes
[[handlerInstance class] getValue];

Yes, like this.

Unlike Java and C++, class methods can only be sent to the class.