当我也可以正常调用该方法时,我应该使用performSelector:吗?

发布于 2024-08-30 20:10:26 字数 270 浏览 0 评论 0原文

我想调用通过[self delegate]获得的对象的方法。我知道它是哪个类,因此我可以导入该类并正常调用它,但我也可以使用 performSelector: ,它不需要导入我的类。我不需要将参数传递给该方法。是的,我确实读过这个。在这种情况下,哪一个更可取?

I want to call a method on an object which I get through [self delegate]. I know which class it is so I can import the class and call it normally but I could also use performSelector: which doesn't require importing my class. I do not need to pass a parameter to the method. And yes, I did read this. Which one is preferable in this case?

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

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

发布评论

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

评论(2

时光磨忆 2024-09-06 20:10:26

直接调用方法更具可读性。 performSelector: 应该在您需要更高阶消息传递时保留。

严格来说,您不需要导入该类来向其发送消息,因为消息调度是动态的而不是静态的,尽管您会收到编译时警告,表明对象可能不会响应选择器。

Calling the method directly is more readable. performSelector: should be reserved for when you need higher order messaging.

Strictly speaking, you don't need to import the class to send it a message as message dispatch is dynamic rather than static, though you will get compile time warnings that the object may not respond to the selector.

提笔落墨 2024-09-06 20:10:26

一般来说,反射操作(例如performSelector:)的效率低于直接操作。不过,我必须承认我对 objC 不是很熟悉。

Generally speaking, reflective operations, such as performSelector:, are less efficient than the direct ones. I have to admit that I am not very familiar with objC, though.

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