1. instancetype 代替 id
@interface MyObject |
- (id)myFactoryMethod; |
@end |
should become:
@interface MyObject |
- (instancetype)myFactoryMethod; |
@end |
Using properties instead of instance variables in as many places as possible provides many benefits:
-
Autosynthesized getters and setters. When you declare a property, by default getter and setter methods are created for you.
-
Better declaration of intent of a set of methods. Because of accessor method naming conventions, it’s clear exactly what the getter and setter are doing.
-
Property keywords that express additional information about behavior. Properties provide the potential for declaration of attributes like
assign
(vscopy
),weak
,atomic
(vsnonatomic
), and so on.
3. object Initialization 对象的初始化
在oc 中,对象的初始化,是基于 “designated initializer”, 它的方法是 调用父类的初始化方法,然后初始化它的成员变量。
4.ARC