"Effective Objective 2.0 study notes"

1 in the class header file to minimize the introduction of other headers, the use of "forward declaration" @class, which can reduce the coupling between classes

With more than two literal syntax, shrinking code size, readability

NSNumber *number = @10086;
NSArray *books = @[@"数据结构与算法",@"java实战"];
NSDictionary *dic = @{@"name":@"金龙鱼",
                        @"age":@18,};

3, when reading the instance variables in the form of direct access, and in the instance variable set when done by property (internal objects)

For the following reasons:

- reason for fast direct access to the instance variable speed is not through Objective-C "approach distribute")
- the big break through the property to access help troubleshoot the problem
- will not trigger the "key observation"
- initialization method and the method delloc It should always be directly read and write by the number of instance variables

4 Multi-use type constants, less #define preprocessor directive (macro checks do not report compilation errors, just replace, const compiles examination, will report compilation errors.)

const NSString *kDebugLoginAccount = @"kDebugLoginAccount"

const NSString *kDebugLoginPassword = @"kDebugLoginPassword"

const NSString *SAVE_PASSWORD_KEY= @"SAVE_PASSWORD_KEY"

 

Guess you like

Origin www.cnblogs.com/jinlongyu123/p/11246384.html