开发者社区> 问答> 正文

[self method] 与 [self performSelector:@selector(method)]之间的区别

如题,既然直接对一个实例发送方法名就可以调用这个方法,那为什么还要使用performSelector:去调呢?两者u有啥区别

展开
收起
a123456678 2016-07-20 14:44:06 1882 0
1 条回答
写回答
取消 提交回答
  • the performSelector: method allows you to send messages that aren’t determined until runtime.
    比如:

    id instance = instance_from_other_module();
    [instance call_undeclared_method];   // 有编译警告
    [instance performSelector:@selector(call_undeclared_method)];
    用这个可以避免编译警告。

    此外,performSelector的其他变体功能,可以用来延时调用和跨线程调用。

    2019-07-17 19:58:51
    赞同 展开评论 打赏
问答地址:
问答排行榜
最热
最新

相关电子书

更多
低代码开发师(初级)实战教程 立即下载
冬季实战营第三期:MySQL数据库进阶实战 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载