官术网_书友最值得收藏!

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)
主站蜘蛛池模板: 河津市| 五常市| 无锡市| 重庆市| 措美县| 嘉禾县| 松阳县| 广平县| 定远县| 麻栗坡县| 彭州市| 莲花县| 高邮市| 东乡| 大方县| 抚松县| 合江县| 萨迦县| 新宾| 界首市| 布拖县| 含山县| 长泰县| 随州市| 古丈县| 镇原县| 金寨县| 宣化县| 岱山县| 喀什市| 襄垣县| 临泉县| 台安县| 景东| 邮箱| 满城县| 微博| 泸水县| 全椒县| 临湘市| 宜章县|