变量
变量名应该尽可能命名为描述性的。除了 for() 循环外,其他情况都应该避免使用单字母的变量名。
星号表示指针属于变量,例如:NSString *text 不要写成 NSString* text 或者 NSString * text ,常量除外。
尽量定义属性来代替直接使用实例变量。除了初始化方法(init, initWithCoder:,等), dealloc 方法和自定义的 setters 和 getters 内部,应避免直接访问实例变量。更多有关在初始化方法和 dealloc 方法中使用访问器方法的信息,参见[这里][Variables_1]。
推荐:
@interface NYTSection: NSObject
反对:
@interface NYTSection : NSObject {
[Variables_1]:https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/MemoryMgmt/Articles/mmPractical.html# //apple_ref/doc/uid/TP40004447-SW6
变量限定符
当涉及到[在 ARC 中被引入][Variable_Qualifiers_1]变量限定符时,
限定符 (__strong, __weak, __unsafe_unretained, __autoreleasing) 应该位于星号和变量名之间,如:NSString * __weak text。
[Variable_Qualifiers_1]:(https://developer.apple.com/library/ios/releasenotes/objectivec/rn-transitioningtoarc/Introduction/Introduction.html# //apple_ref/doc/uid/TP40011226-CH1-SW4)
