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

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. 

主站蜘蛛池模板: 玉屏| 平舆县| 元阳县| 报价| 防城港市| 嵊泗县| 五家渠市| 饶平县| 西贡区| 高安市| 新津县| 朝阳区| 兰西县| 吉安市| 城口县| 社会| 当涂县| 苗栗县| 沙河市| 西城区| 方山县| 冀州市| 冀州市| 泽州县| 望都县| 合作市| 万山特区| 金堂县| 汝南县| 莱西市| 翼城县| 南宫市| 沅陵县| 中阳县| 施秉县| 宜城市| 山西省| 高雄县| 罗定市| 东乌| 霍邱县|