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

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)
主站蜘蛛池模板: 合水县| 理塘县| 区。| 泰来县| 海林市| 庆城县| 海口市| 泸西县| 惠东县| 上栗县| 定安县| 镇赉县| 淅川县| 奉贤区| 上思县| 射阳县| 泗阳县| 左云县| 城固县| 榆林市| 皋兰县| 文水县| 民丰县| 淮北市| 临邑县| 商都县| 乌恰县| 锡林浩特市| 西乡县| 团风县| 济源市| 甘南县| 灵璧县| 无为县| 东至县| 南部县| 中卫市| 石嘴山市| 天峻县| 渝北区| 耒阳市|