NSObject中的performSelector用法簡介

來源:互聯網
上載者:User

標籤:des   style   color   io   os   使用   ar   for   strong   

- (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

[參數]

aSelector

A selector identifying the message to send. If aSelector is NULL, an NSInvalidArgumentException is raised.

[選取器確定要發送的訊息。如果aSelector為NULL,一個NSInvalidArgumentException提高。]

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用法簡介

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.