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

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)
主站蜘蛛池模板: 淄博市| 东丽区| 民和| 华亭县| 突泉县| 栖霞市| 当阳市| 拜城县| 河北省| 辛集市| 澳门| 江门市| 大名县| 永修县| 石家庄市| 淮安市| 杭州市| 精河县| 芒康县| 安岳县| 古丈县| 望江县| 宁乡县| 霍城县| 安丘市| 静安区| 永年县| 洞口县| 武功县| 柳林县| 许昌县| 宝鸡市| 若羌县| 潍坊市| 洪雅县| 万全县| 南康市| 武穴市| 南郑县| 澄城县| 中卫市|