You can use isKindOfClass
to find whether or not an id
is a protocol:
id x = [NSObject class];
id y = @protocol(NSObject);
NSLog(@"%d", [x isKindOfClass:[Protocol class]]); // 0
NSLog(@"%d", [y isKindOfClass:[Protocol class]]); // 1
You have to import the ObjectiveC.Protocol
module to use Protocol
:
@import ObjectiveC.Protocol;
Or if you are not using modules, just import the Protocol header:
#import <objc/Protocol.h>
To check if an id
is a class or an instance have a look a this answer