📂
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 規則

程式格式(Format)

一個Tab是4空格(Xcode預設)

所有冒號和逗號的左邊不留空,右邊留空

// 冒號左邊不留空,右邊留空
@IBOutlet weak var tableView: UITableView!
    
// 冒號和逗號左邊不留空,右邊留空
private func initTableView(index: Int, name: String) {
    //....
}

三元判斷式,冒號左右都留空

// 冒號左右都留空
let dataCount = isGetDataDone ? listCount : 0

程式碼禁止結尾加上分號

// 禁止加上分號
let count = 0

請用extension區隔不同的protocol或是功能

// MARK: - UIScrollViewDelegate
extension PageControlScrollView: UIScrollViewDelegate {
    //....
}

// MARK: - UITableViewDataSource
extension PageControlScrollView: UITableViewDataSource {
    //....
}

// MARK: - 股票相關
extension PageControlScrollView{
    //股票相關的方法...
}

// MARK: - 動畫相關
extension PageControlScrollView{
    //動畫相關的方法...
}
Previous命名(Naming)Next註解(Comment)

Last updated 4 years ago

Was this helpful?