Here’s my situation:
I have a protocol with a class method that parses an NSDictionary and returns an object that performs my protocol:
@protocol RCParsableObject <NSObject>
/**
Parses an object from an NSDictionary representation
Return: A object created from the NSDictionary representation
*/
+(id<RCParsableObject>)parseObjectFromDictonary:(NSDictionary*)object;
@end
At a part of my code I have the name of a class that performs that protocol in an NSString:
//dict is the dictionary I want to parse
Class class= NSClassFromString(type);
if ([class conformsToProtocol:@protocol(RCParsableObject)]) {
//NSObject* object = [class parseObjectFromDictionary:dict];//Obviously that don't works but shows what I want
}
Inside the if I want to perform the Class method of the protocol that I know it can be performed because of the if. How I can do that? It’s a equivalent to:
NSObject * object = [class performSelector:_selector];
For a Class object?
That is how you’d do it, except you’ll want to type the variable holding the return value as
idorid<RCParsableObject>. No need forperformSelector:or anything like it — that’s useful for when the selector is dynamically chosen, which isn’t the case here.