How to init NSObject<protocol> pointer so it responds to delegate SEL?
I have such thing in my class definition:
NSObject<SomeProtocol> *dataDelegate;
I have custom -(id)init
method i开发者_JS百科n which I should init this NSObject
. How do I do it if I want it to respond selectors from SomeProtocol
?
If you have a class declared to implement SomeProtocol
, then you'd just do:
@interface SomeClass:NSObject <SomeProtocol>
.... etc ....
And in the implementation:
dataDelegate = [SomeClass new]; // or alloc/init
You just need to create an instance of a class that implements the protocol.
精彩评论