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方法,不能用在通用方法里。
注:點語法的本質(zhì)還是方法調(diào)用,使用點語法的時候,系統(tǒng)會自動展開成相應的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里,空對象在功能上等同于空指針,和其他語言的不同在于,調(diào)用空方法不會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創(chuàng)建了一個對象,必須在后期將其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.