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

類別與結構(Classes and Structures)

一個屬性佔一行 ,禁止單行宣告多個屬性

類別內部呼叫成員禁止加self,除非與參數衝名或是必要狀況

/// 圓形類別
class Circle: Shape {
        
    /// 圓心的x(禁止單行宣告多個變數)
    private var x: Int
    
    /// 圓心的y
    private var y: Int
  
    /// 初始化(初始化時參數丟入相同名稱的變數要加self)
    init(x: Int, y: Int) {
        self.x = x
        self.y = y
    }
}

禁止在Class外宣告變數或方法,不易管理和閱讀

// Class外宣告變數
let globalData = 100

/// 圓形類別
class Circle: Shape {
    // ...
}

Previous註解(Comment)Next修飾詞(Modifier)

Last updated 4 years ago

Was this helpful?