From the course: Swift 5: Protocol-Oriented Programming

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Introducing the protocol

Introducing the protocol

From the course: Swift 5: Protocol-Oriented Programming

Start my 1-month free trial

Introducing the protocol

- [Instructor] Protocols stand at the core of POP. They model abstraction by describing what the conforming types shall implement. Protocol names must begin with a capital letter. Apple has clear recommendations regarding protocol naming. Protocols that describe what something is should read as nouns. For example, collection, UITableViewDataSource, or UITextFieldDelegate. Protocols that describe a capability should be named using the suffixes able, ible, or ing. Such a Codable, CustomStringConvertible, and NSCoding. Let's get started exploring the protocol syntax. Open up Xcode and create a playground called protocols. Let's make it full screen and I'm going to remove the generated code except the import will need Foundation. All right, we declare a protocol called Taggable. I'm using the protocol keyword and let's call it Taggable. The protocol definition, that is the method and the calculated property requirements go…

Contents