一、類
- 與XxYyyController對應的xib文件應該命名爲XxYyy。
- 類中功用相同的成員應以tab對齊。不同功用的成員變量(以及對應的property)、成員函數前後以空行隔開。
- 先寫property,再寫靜態函數,再寫成員函數
123456789
@property
(
nonatomic
,
retain
)
NSData
*channelListXMLData;
+ (ViewSwitcher *)getInstance;
+ (
void
)destoryInstance;
- (
void
)showWelcomeView;
- (
void
)showMenuView;
- (
void
)showChannelView;
- (
void
)showArticleView;
二、函數和語句
- 函數的-+標識符後應緊接一個空格,返回值的括號右側緊跟函數名
- 函數的形參若與類成員變量衝突,如scrollView,則使用theScrollView或者aScrollView這樣的形式
- 函數的大括號使用蘋果xcode預定義的方式:前大括號不換行,前面加一個空格
- 函數創建的內存:誰創建,誰銷燬。函數名中不含有new、alloc、create、copy的,返回值都應該是autorelease的對象。反之,創建的內存由調用者釋放。
- 語句中:二元操作符(- + = == < >)左右都有空格,一元操作符僅左邊(或者右邊)有空格
123
i = i +
1
;
if
(xTmp = ++i) { doSomeThing(); }
if
(i-- == xTmp) { whyDoYouDoThis(shit) }
- 太長且有視覺上的重複性的代碼,使用有意義的折行:
123456
return
[
NSString
stringWithFormat
:
@
"%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x"
,
result
[0
], result
[1
], result
[2
], result
[3
],
result
[4
], result
[5
], result
[6
], result
[7
],
result
[8
], result
[9
], result
[10
], result
[11
],
result
[12
], result
[13
], result
[14
], result
[15
]
];
三、變量
- 統一使用UI庫封裝的基本類型,如NSInteger CGFloat,而不是int float