📂
CMiOSBook
  • CMoney iOS Book
  • Coding 101
    • Value / Reference Type
    • ARC + Retain Cycle
    • 物件之間的溝通方式
  • 工具主題
    • 基本工具篇
    • Git 篇
  • 架構主題
    • MVC
  • CodingStyle主題
    • CodingStyle 規則
      • 專案(Project)
      • 命名(Naming)
      • 程式格式(Format)
      • 註解(Comment)
      • 類別與結構(Classes and Structures)
      • 修飾詞(Modifier)
      • 閉包表達式(Closures)
    • 靜態檢查器
    • 專案基本規定
  • UI主題
    • UIScrollViewDelegate & UITableViewDelegate
  • Charts主題
    • 簡介
    • Lesson1 Chart Setup
    • Lesson2 Chart Data
    • Lesson3 CombinedChartView
    • Lesson4 Renderer
  • Test主題
    • 單元測試的基本概念
    • XCTest-UnitTest
    • XCTest-UITest
  • 學習資源
    • 相關網站
    • 相關會議與社群
    • 計算機考題
Powered by GitBook
On this page

Was this helpful?

  1. CodingStyle主題
  2. CodingStyle 規則

命名(Naming)

命名一律駝峰式,不論存取權限、不論常數或變數

  • 開頭必大寫:Class(類別)、Structure(結構)、Enum(列舉)、Protocol(協議)

  • 開頭必小寫:Function(方法)、Field(變數)、Property(屬性)、列舉內部的Case

禁止全大寫和底線式

class WidgetContainer { //大寫開頭駝峰式
    var widgetButton: UIButton //小寫開頭駝峰式
    let widgetHeightPercentage = 0.85 //小寫開頭駝峰式
}

enum Shape {
    case rectangle //列舉內部的case小寫開頭駝峰式
    case square
}

備註:如果後台傳回來的json轉換出的物件,欄位是大寫,可使用CodingKey的方式解析。

public class GetLoginGuidResponse: CMoneyResponseBase, Codable {
    public var guid: String = ""
    public var authToken: String  = ""
    public var memberPk: Int = 0

    /// CodingKeys
    public enum CodingKeys: String, CodingKey {
        case guid = "Guid"
        case authToken = "AuthToken"
        case memberPk = "MemberPk"
    }
}

建議使用有意義的命名,該命名盡可能符合該變數所具有的功能

a, b, temp1, temp2, nameA, nameB 這一類的命名方式都是不好的

Previous專案(Project)Next程式格式(Format)

Last updated 4 years ago

Was this helpful?