- Hands-On Design Patterns with Swift
- Florent Vilmart Giordano Scalzo Sergio De Simone
- 71字
- 2021-07-02 14:45:00
Conformance at declaration
The first method to declare a conformance is to do it at the top level, when you declare your custom type. You'll notice that the raw representation comes first, then the protocol conformance:
enum State: Int, Toggling {
case off = 0
case on
mutating func toggle() {
self = self == .on ? .off : .on
}
}
var state: State = .on
state.toggle()
assert(state == .off)
推薦閱讀
- 數(shù)據(jù)庫基礎(chǔ)與應(yīng)用:Access 2010
- 虛擬化與云計算
- 正則表達(dá)式必知必會
- Access 2007數(shù)據(jù)庫應(yīng)用上機指導(dǎo)與練習(xí)
- 分布式數(shù)據(jù)庫系統(tǒng):大數(shù)據(jù)時代新型數(shù)據(jù)庫技術(shù)(第3版)
- SQL查詢:從入門到實踐(第4版)
- R數(shù)據(jù)科學(xué)實戰(zhàn):工具詳解與案例分析(鮮讀版)
- iOS and OS X Network Programming Cookbook
- 城市計算
- 智能數(shù)據(jù)時代:企業(yè)大數(shù)據(jù)戰(zhàn)略與實戰(zhàn)
- 淘寶、天貓電商數(shù)據(jù)分析與挖掘?qū)崙?zhàn)(第2版)
- SQL Server 2012實施與管理實戰(zhàn)指南
- MySQL DBA修煉之道
- 云計算
- Spring Boot 2.0 Cookbook(Second Edition)