Swift3.0 - 真的很簡(jiǎn)單
Swift3.0 - 數(shù)據(jù)類型
Swift3.0 - Array
Swift3.0 - 字典
Swift3.0 - 可選值
Swift3.0 - 集合
Swift3.0 - 流控制
Swift3.0 - 對(duì)象和類
Swift3.0 - 屬性
Swift3.0 - 函數(shù)和閉包
Swift3.0 - 初始化和釋放
Swift3.0 - 協(xié)議protocol
Swift3.0 - 類和結(jié)構(gòu)體的區(qū)別
Swift3.0 - 枚舉
Swift3.0 - 擴(kuò)展
Swift3.0 - 下標(biāo)
Swift3.0 - 泛型
Swift3.0 - 異常錯(cuò)誤
Swift3.0 - 斷言
Swift3.0 - 自動(dòng)引用計(jì)數(shù)(strong,weak,unowned)
Swift3.0 - 檢測(cè)API
Swift3.0 - 對(duì)象的標(biāo)識(shí)
Swift3.0 - 注釋
Swift3.0 - 元類型
Swift3.0 - 空間命名
Swift3.0 - 對(duì)象判等
Swift3.0 - 探究Self的用途
Swift3.0 - 類簇
Swift3.0 - 動(dòng)態(tài)調(diào)用對(duì)象(實(shí)例)方法
Swift3.0 - 文本輸出
Swift3.0 - 黑魔法swizzle
Swift3.0 - 鏡像
Swift3.0 - 遇到的坑
- 類簇
使用一個(gè)統(tǒng)一的接口制定單一的對(duì)象
示例代碼:
class Drinking: NSObject{
class func drink(name:String) -> Drinking?{
var drink: Drinking?
switch name {
case "Coke" : drink = Coke(name: name)
case "Beer" : drink = Beer(name: name)
default :break;
}
return drink
}
}
class Coke:Drinking {
var name:String
init(name: String) {
self.name = name
}
}
class Beer:Drinking {
var name:String
init(name: String) {
self.name = name
}
}
let coke = Drinking.drink(name: "Coke") as! Coke
print(coke.name)
運(yùn)行結(jié)果:
Coke