首页 > 代码库 > NSObject中的performSelector用法简介
NSObject中的performSelector用法简介
- (id)performSelector:(SEL)aSelector | |||
Description [说明] | Sends a specified message to the receiver and returns the result of the message. (required) [发送指定消息的接收和返回消息的结果。(必填)] | ||
| The performSelector: method is equivalent to sending an aSelector message directly to the receiver. For example, all three of the following messages do the same thing: [该performSelector:方法等效于直接发送aSelector消息发送到接收器。举例来说,所有这三个以下消息做同样的事情:]
id myClone = [anObject copy]; id myClone = [anObject performSelector:@selector(copy)]; id myClone = [anObject performSelector:sel_getUid("copy")];
However, the performSelector: method allows you to send messages that aren’t determined until runtime. A variable selector can be passed as the argument: [然而,performSelector:方法允许你发送那些没有确定,直到运行时的消息。变量选择器可作为参数传递:]
SEL myMethod = findTheAppropriateSelectorForTheCurrentSituation(); [anObject performSelector:myMethod];
The aSelector argument should identify a method that takes no arguments. For methods that return anything other than an object, use NSInvocation. [该aSelector参数应该找出一种方法,它没有参数。对于返回以外的任何一个对象的方法,使用NSInvocation。] | ||
Parameters [参数] |
| ||
Returns [返回] | An object that is the result of the message. [一个对象,该对象是消息的结果。] | ||
Availability [可用性] | OS X (10.0 and later) [OS X 10.0及更高版本] | ||
Declared In [宣称] | NSObject.h | ||
Reference [参考] | NSObject Protocol Reference [参考NSObject协议] |
NSObject中的performSelector用法简介