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.
Conforming to protocols via extensions
From the course: Swift 5: Protocol-Oriented Programming
Conforming to protocols via extensions
- [Narrator] Developers often rely on code they do not own. That's the case when working with SDKs and third-party libraries. I create a new playground called ProtocolConformance. Now, let's assume that we want to build a cryptography framework. We start with a protocol, but first, I'm going to to remove the generated code, we only need to keep the foundation framework and the rest will be deleted. So let's create the protocol, I'm going to call it encrypting, and it defines a single-method requirement, the XOR method. It takes a parameter called key of type onsite integer, and it returns option of self. We can adopt this protocol in our types easily. If I create a structure like TaggedData, Xcode will help out and create the stubs, and I could provide the implementation here. Now, what if I want to make the string type conform to the protocol? We can't change the implementation of the string's structure as we did with…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
What is protocol-oriented programming?2m 15s
-
(Locked)
Introducing the protocol5m 18s
-
(Locked)
Adopting protocols1m 54s
-
(Locked)
Conforming to protocols via extensions3m 38s
-
(Locked)
Understanding polymorphism4m
-
(Locked)
Protocol inheritance3m 41s
-
(Locked)
Adopting multiple protocols5m 50s
-
(Locked)
Protocol extensions3m 23s
-
(Locked)
Challenge: Removing tight coupling3m 13s
-
(Locked)
Solution: Removing tight coupling8m 33s
-
-
-
-
-