注释规范
一. 模块分割注释:使用//MARK: -
,等价于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
注释、使用///
/// 创建一个网络协议,使其具备网络请求的条件
protocol FSNetworkable {
/// 域名
var baseURL: String! { get }
}
三. 方法注释:选中方法,然后alt+command+/
,效果如下:
/// 这是一个示例方法
/// - Parameters:
/// - a:这个参数的作用是。。。
/// - Returns: 返回值
func test(a: Int) -> String {
return a*2
}
四. 函数内部注释:短注释用//
,长注释用/**这是注释信息*/
命名规范
一. 文件名
遵循大驼峰命名法
二. class
、struct
、enum
、protocol
遵循大驼峰命名法
- .protocol
用来表示是什么时使用名词,如Collection
,用来描述能力使用ing
、able
、ible
结尾,遵循接口隔离原则
三. 方法名
、属性名
、参数名
、枚举的case
遵循小驼峰命名法