如何初始化 NSObject<协议>指针,以便它响应委托 SEL?

发布于 2024-09-18 20:58:03 字数 213 浏览 2 评论 0原文

我的类定义中有这样的内容:

NSObject<SomeProtocol> *dataDelegate;

我有自定义的 -(id)init 方法,我应该在其中初始化这个 NSObject。如果我希望它响应 SomeProtocol 中的选择器,我该怎么做?

I have such thing in my class definition:

NSObject<SomeProtocol> *dataDelegate;

I have custom -(id)init method in which I should init this NSObject. How do I do it if I want it to respond selectors from SomeProtocol?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

幸福还没到 2024-09-25 20:58:03

如果您有一个声明为实现 SomeProtocol 的类,那么您只需执行以下操作:

@interface SomeClass:NSObject <SomeProtocol>
.... etc ....

在实现中:

dataDelegate = [SomeClass new]; // or alloc/init

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
暖风昔人 2024-09-25 20:58:03

您只需要创建一个实现该协议的类的实例。

You just need to create an instance of a class that implements the protocol.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文