IOS類方法,執行個體方法

來源:互聯網
上載者:User

標籤:

從昨天開始準備從Objective-C Programming: The Big Nerd Ranch Guide這本書入手,從頭紮實地學習一下OC,順便提高一下英文閱讀能力。

今天的知識重點在於類方法和執行個體方法的區別:

NSDate *now = [NSDate date];

We say that the date method is a class method. That is, you cause the method to execute by sending a message to the NSDate class. The date method returns a pointer to an instance of NSDate.

date是一種類方法,你發送訊息的目標是NSDate類,該方法傳回值為一個NSDate的執行個體指標。

double seconds = [now timeIntervalSince1970];

We say that timeIntervalSince1970 is an instance method. You cause the method to execute by sending a message to an instance of the class. The timeIntervalSince1970 method returns a double.

timeIntervalSince1970是一種執行個體方法,你執行該方法時發送訊息的目標是類的一個執行個體,該方法傳回值為一個double型變數。

NSDate *later = [now dateByAddingTimeInterval:100000];

dateByAddingTimeInterval: is another instance method. This method takes one argument. You can determine this by the colon in the method name. This method also returns a pointer to an instance of NSDate.

dateByAddingTimeInterval是另一種執行個體變數。該方法需要一個參數。通過方法名中的冒號區分。該方法同樣返回一個指向NSDate執行個體的指標。

 

IOS類方法,執行個體方法

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.