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

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

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


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的其他变体功能,可以用来延时调用和跨线程调用。

【热门文章】
【热门文章】