开发者

How to init NSObject<protocol> pointer so it responds to delegate SEL?

开发者 https://www.devze.com 2023-01-15 07:00 出处:网络
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 t

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消