Difference between id <protocol> and NSObject <protocol>
1 answer
id<protocol> obj is the declaration for any object that conforms to the specified protocol. You can send any message from this protocol to the object (or from protocols that <protocol> inherited from).
NSObject<protocol> *obj is an ad for any object that
- complies with this protocol and
NSObjectfromNSObject.
This means that in the second case, you can send any methods from the NSObject class to the object, for example
id y = [obj copy]; which will give a compiler error in the first case.
The second declaration also implies that obj conforms to the NSObject protocol. But it doesnβt matter if the <protocol> obtained from the NSObject protocol:
@protocol protocol <NSObject> +8