注釋規(guī)范
一. 模塊分割注釋:使用//MARK: -
,等價(jià)于OC中的#pragma mark
// MARK: - UITableViewDataSource
extension FSViewControler: UITableViewDataSource {
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 1
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
return UITableViewCell()
}
}
二. 屬性注釋紧显、枚舉的case
注釋肪获、使用///
/// 創(chuàng)建一個(gè)網(wǎng)絡(luò)協(xié)議爹土,使其具備網(wǎng)絡(luò)請(qǐng)求的條件
protocol FSNetworkable {
/// 域名
var baseURL: String! { get }
}
三. 方法注釋:選中方法,然后alt+command+/
,效果如下:
/// 這是一個(gè)示例方法
/// - Parameters:
/// - a:這個(gè)參數(shù)的作用是。盏道。。
/// - Returns: 返回值
func test(a: Int) -> String {
return a*2
}
四. 函數(shù)內(nèi)部注釋:短注釋用//
,長(zhǎng)注釋用/**這是注釋信息*/
命名規(guī)范
一. 文件名
遵循大駝峰命名法
二. class
载碌、struct
猜嘱、enum
、protocol
遵循大駝峰命名法
- .protocol
用來(lái)表示是什么時(shí)使用名詞嫁艇,如Collection
,用來(lái)描述能力使用ing
朗伶、able
、ible
結(jié)尾步咪,遵循接口隔離原則
三. 方法名
论皆、屬性名
、參數(shù)名
歧斟、枚舉的case
遵循小駝峰命名法