Swift關(guān)鍵字
- associatedtype: 協(xié)議-關(guān)聯(lián)類型抡句, 作用:為協(xié)議中的某個類型提供了一個占位名(或者說別名)
- inout: 輸入輸出參數(shù)惕蹄,作用:修飾參數(shù)標(biāo)簽淑廊,是該參數(shù)在此函數(shù)體內(nèi)粗俱,可修改蜻展。
- operator: 操作符魁亦,自定義操作符時渔隶,必帶。
- class: 其中一個作用是:修飾類方法洁奈、類屬性(類屬性:只有在這個類第一次訪問時间唉,才被初始化,線程安全)利术。
- static:其中一個作用是:修飾類方法呈野、類屬性。結(jié)構(gòu)體印叁、枚舉只能使用關(guān)鍵字static修飾
- struct: 聲明結(jié)構(gòu)體被冒。
- subscript:下標(biāo)。語法:subscript(index:type) ->returnType { get{} set{} }
- typealias: 起別名
- defer: 將代碼的執(zhí)行延遲到當(dāng)前的作用域退出之前轮蜕。注意:內(nèi)部不能包含任何控制轉(zhuǎn)移語句昨悼。(應(yīng)用場景,打開時數(shù)據(jù)庫跃洛,關(guān)閉數(shù)據(jù)庫幔戏。獲取圖形上下文,關(guān)閉圖形上下文)
- fallthrough: swich中貫穿
- guard: guard else{} 提前終止
- in: 閉包中作用:表示閉包的參數(shù)和返回值類型的定義已經(jīng)完成税课,閉包函數(shù)體即將開始闲延。
- repeat: repeat{}while 表達(dá)式痊剖; 相當(dāng)于do{}while 表達(dá)式;
- where: 條件語句垒玲,where具體用途
- is: 能否向下轉(zhuǎn)變
- as: 向上轉(zhuǎn)變或橋接陆馁。(向超類轉(zhuǎn)變)
- as?:返回可選值
- as! : 強(qiáng)制類型轉(zhuǎn)變合愈,轉(zhuǎn)變失敗叮贩,導(dǎo)致運(yùn)行時錯誤。
- @IBDesignable dynamic,eg:open dynamic var textColor: UIColor;能在xib中顯示設(shè)置項 TagListView
- associativity: 自定義操作符時佛析,指定優(yōu)先級益老。associativity
- final:防止重寫
- Indirect:枚舉遞歸
- self和Self
fileprivate func < <T : Comparable>(lhs: T?, rhs: T?) -> Bool {
switch (lhs, rhs) {
case let (l?, r?):
return l < r
case (nil, _?):
return true
default:
return false
}
}
fileprivate func >= <T : Comparable>(lhs: T?, rhs: T?) -> Bool {
switch (lhs, rhs) {
case let (l?, r?):
return l >= r
default:
return !(lhs < rhs)
}
}