美文网首页
swift代码规范

swift代码规范

作者: 热望与美梦 | 来源:发表于2018-07-18 17:29 被阅读0次

代码规范整理

安装swifLint

http://www.cocoachina.com/ios/20170602/19415.html?utm_source=debugrun&utm_medium=referral

执行脚本:

if which swiftlint >/dev/null;then

swiftlint

else

echo "warning: SwiftLint not installed,download from https://github.com/realm/SwiftLint"

fi

1.

 @objcstatic var height_NavigateBar: CGFloat {

        return isIphoneX ? 88 : 64

    }

Identifier Name Violation: Variable name should only contain alphanumeric characters: 'height_NavigateBar'(identifier_name)

2.

   typealiascallback =(AlertAction)-> Void

Type Name Violation: Type name should start with an uppercase character: 'callback'(type_name)

3.

let point =(touchas! UITouch).location(in: nil)

Force Cast Violation: Force casts should be avoided.(force_cast)

4.

 let t = timer 

  for i in urlStr.components(separatedBy: "&")

Identifier Name Violation: Variable name should be between 3 and 40 characters long: 'i'(identifier_name)

5.

     let strSize: CGRect =(NSString.init(string: titleLabel!.text!)).boundingRect(with: CGSize.init(width: CGFloat(MAXFLOAT),height: 0.0),options: .usesLineFragmentOrigin,attributes:[NSAttributedStringKey.font: UIFont.systemFont(ofSize: 14)],context: nil)

        if self.thirdInsurance.value == nil || self.carLose.value == nil || self.carRob.value == nil || self.glassInsurance.value == nil || self.nonDutyInsurance.value == nil || self.passengerDutyInsurance.value == nil || self.carScratchInsurance.value == nil || self.crossWaterInsurance.value == nil {

            return

        }

Line Length Violation: Line should be 120 characters or less: currently 264 characters(line_length)

修改格式如下:

  let strSize: CGRect =(NSString.init(string: titleLabel!.text!)).boundingRect(with: CGSize.init(width: CGFloat(MAXFLOAT),height: 0.0),

            options: .usesLineFragmentOrigin,

            attributes:[NSAttributedStringKey.font: UIFont.systemFont(ofSize: 14)],context: nil)

   func calculateCommericalCost(){

        if self.thirdInsurance.value == nil ||

            self.carLose.value == nil ||

            self.carRob.value == nil ||

            self.glassInsurance.value == nil ||

            self.nonDutyInsurance.value == nil ||

            self.passengerDutyInsurance.value == nil ||

            self.carScratchInsurance.value == nil ||

            self.crossWaterInsurance.value == nil {

            return

        }

6.

    public enum AlertViewType: Int {

        casePriceType = 1

        caseSortType  = 2

        caseMoreType = 3

    }

Identifier Name Violation: Enum element name should start with a lowercase character: 'PriceType'(identifier_name)

7.

    private lazyvar CarHistoryPath: URL = {

        let manager = FileManager.default

        var filePath = manager.urls(for: .documentDirectory,in: .userDomainMask).first

        filePath!.appendPathComponent("carModelsHistory.archive")

        return filePath!

    }()

Identifier Name Violation: Variable name should start with a lowercase character: 'CarHistoryPath'(identifier_name)

8.

文件代码行数超过400行

File Line Length Violation: File should contain 400 lines or less: currently contains 1199(file_length)

9.

   currentPag = currentPag + 1

Shorthand Operator Violation: Prefer shorthand operators(+=,-=,*=,/=)over doing the operation and assigning.(shorthand_operator)

相关文章

  • Raywenderlich 的 Swift 代码规范

    Raywenderlich 的 Swift 代码规范

  • Swift代码规范

    团队的Swift代码规范,参考Swift Style Guide和Swift 4.0 编码规范,并根据团队实际需要...

  • 常用技术网址

    代码规范: 代码规范 网站: CocoaChina Apple文档 swift.gg code4app stack...

  • Swift 代码规范中文-Swift Style Guide

    Swift Style Guide Swift代码规范指南 Make sure to read Apple's A...

  • 一篇详细的swift代码规范

    【转载】转自卓大大翻译谷歌的swift代码规范 [译] 官方 Swift API 设计规范 官方地址:API de...

  • swift代码规范

    代码规范整理 安装swifLint http://www.cocoachina.com/ios/20170602/...

  • Swift代码规范

    当你试图解决一个别人代码中的问题时,难得不是怎么解决这个问题,而是先得找到、读懂这段代码。 推荐文档:https:...

  • Swift代码规范

    推荐个规范代码的库SwiftLint, 有兴趣的同学可瞧瞧如何。相信我,关于代码规范,你需要仔细看看这篇文章最详尽...

  • Swift代码规范

  • Swift 代码规范

    目录 源文件基础知识文件名文件编码空白字符特殊转义序列不可见的字符和修饰符字符串字面量不可见的字符和修饰符 源文件...

网友评论

      本文标题:swift代码规范

      本文链接:https://www.haomeiwen.com/subject/nlhapftx.html