Swift开发规范

2022-08-23  本文已影响0人  一把好刀

注释规范

一. 模块分割注释:使用//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
}

四. 函数内部注释:短注释用//,长注释用/**这是注释信息*/

命名规范

一. 文件名遵循大驼峰命名法

二. classstructenumprotocol 遵循大驼峰命名法
- .protocol用来表示是什么时使用名词,如Collection,用来描述能力使用ingableible结尾,遵循接口隔离原则

三. 方法名属性名参数名枚举的case遵循小驼峰命名法

上一篇下一篇

猜你喜欢

热点阅读