- Hands-On Design Patterns with Swift
- Florent Vilmart Giordano Scalzo Sergio De Simone
- 116字
- 2021-07-02 14:45:00
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.
推薦閱讀
- 同步:秩序如何從混沌中涌現(xiàn)
- 文本挖掘:基于R語(yǔ)言的整潔工具
- Enterprise Integration with WSO2 ESB
- 數(shù)字媒體交互設(shè)計(jì)(初級(jí)):Web產(chǎn)品交互設(shè)計(jì)方法與案例
- MySQL 8.x從入門到精通(視頻教學(xué)版)
- Oracle PL/SQL實(shí)例精解(原書第5版)
- SQL Server 2012數(shù)據(jù)庫(kù)管理教程
- INSTANT Android Fragmentation Management How-to
- 區(qū)塊鏈技術(shù)應(yīng)用與實(shí)踐案例
- 貫通SQL Server 2008數(shù)據(jù)庫(kù)系統(tǒng)開發(fā)
- 活用數(shù)據(jù):驅(qū)動(dòng)業(yè)務(wù)的數(shù)據(jù)分析實(shí)戰(zhàn)
- 數(shù)據(jù)庫(kù)原理及應(yīng)用:SQL Server 2016
- 大數(shù)據(jù)技術(shù)體系詳解:原理、架構(gòu)與實(shí)踐
- Artificial Intelligence for Big Data
- Arquillian Testing Guide