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

Declaring a protocol

You declare protocols using the protocol keyword, as follows:

protocol Toggling {
mutating func toggle()
}

Now that this protocol has been declared, any time that you declare a type conforming to Toggling, you'll be required to implement a mutating toggle() function.

You can use protocols in your type declarations, method declarations, or variable declarations. While it is technically possible to use protocols as interfaces for your objects or structs, that is usually not how they are used in Swift. Often, you will find yourself conforming to protocols when declaring your custom types or later in your code base, part of extending your existing type to bring additional functionality to it. 

主站蜘蛛池模板: 文水县| 四子王旗| 嘉禾县| 桂东县| 株洲县| 和龙市| 巴林右旗| 平山县| 揭阳市| 汤阴县| 姚安县| 海城市| 和硕县| 鄂托克旗| 壤塘县| 苗栗市| 龙海市| 潜江市| 衡山县| 宁陵县| 镇坪县| 通州区| 屏边| 新闻| 措勤县| 商南县| 汕头市| 孝义市| 乌鲁木齐市| 建瓯市| 彭水| 上高县| 灵台县| 涞源县| 武安市| 徐闻县| 尼木县| 扶风县| 乌兰浩特市| 许昌市| 三江|