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.

你可能感兴趣的:(Notes for《Learn Objective-C》)