In my application, I need to return the “Class” as a return type like:
Application.m:
+ (Class)getParserClass {
return [NCCurrencyParser class];
}
NCCurrencyParser.m:
@interface NCCurrencyParser NSObject <NCParser>
@protocol NCParser
+(NSNumber *)parserNumber:(NSNumber *)number;
in the caller method:
Class parserClass = [Application getParserClass];
[parserClass parserNumber:1.0];
But then the compiler gives me the error that parserClass may not respond to parseNumber. How can I force the Class have to adopt to some protocol like : Class <NCParser> (but it doesn’t work)
Class objects in Objective-C are first class objects, and can can implement protocols like any other Objective-C object (id, NSObject*, …)
So just do whatever you would normally do for any other Object protocol, ie:
And
Build/Compiled/Tested on xcode 3.2.3, iPhone Simulator 4.0, GCC 4.2