Notes for《Learn Objective-C》

contents

* Calling Methods

* Accessors

* Creating Objects

* Basic Memory Management?

* Designing a Class Interface

* Class Implementation

* More on Memory Management

* Logging

* Properties

* Calling Methods on Nil

* Categories

notes

1. Dot Syntax

The dot syntax should only be used setters and getters, not for general purpose methods.

點語法只能用于set和get方法,不能用在通用方法里。

注:點語法的本質還是方法調用,使用點語法的時候,系統會自動展開成相應的set和get方法。

2. Calling Methods on Nil

In Objective-C, the nil object is the functional equivalent to the NULL pointer in many other languages. The difference is that you can call methods on nil without crashing or not an exception.

OC里,空對象在功能上等同于空指針,和其他語言的不同在于,調用空方法不會crash。

3. Basic Memory Management

If you create an object using the manual alloc style, you need to release the object later. You should not manually release an autoreleased object because your application will crash if you do.

如果用alloc創建了一個對象,必須在后期將其release。不能手動release一個會自動release的對象,因為這么做會crash。

4. Calling Methods on Nil

Note that we're using theself.syntax here, which means we're using the setter and picking up the memory management for free.

5. Categories

A category allows you to add methods to an existing class without subclassing it or needing to know any of the details of how it's implemented.

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容