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

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. 

主站蜘蛛池模板: 连山| 会宁县| 读书| 呈贡县| 宁明县| 合肥市| 隆德县| 五大连池市| 五寨县| 江孜县| 鄂尔多斯市| 九龙坡区| 宿迁市| 灌阳县| 互助| 汾阳市| 浠水县| 文山县| 手游| 秦皇岛市| 赣榆县| 随州市| 望谟县| 阿拉尔市| 沿河| 麦盖提县| 定州市| 缙云县| 禹州市| 崇仁县| 吉水县| 土默特右旗| 积石山| 青神县| 罗平县| 明溪县| 鸡西市| 武乡县| 曲松县| 祁门县| 麻阳|