swift代码规范

代码规范整理

安装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)

你可能感兴趣的:(swift代码规范)