Protocols can also work with placeholder types. In this video, learn about associated types.
- [Instructor] So far, we've looked at the benefits of…genetic types and functions and how to use them.…How about protocols?…Lets take a look at the Binary Representable protocol.…It defines requirements for any type that can hold…binary data and uses a deck to identify it.…Wouldn't it be great to create a protocol…that is not not restricted to the data pack?…Swift lets us do that.…I'll create a new playground page for this project.…Let's call it "Associated Type".…
I'm going to clean up…because we only need to import the foundation framework.…Next, I'm going to create a new protocol…called "Any Representable".…Protocol, any representable.…I declare an associated type called "Content Type".…The associated type keyword let's us define…placeholder types.…A place holder type is unknown until…a conforming type provides it.…
Then, I add a tag which is of type "String".…Get bar and set bar.…Then, we'll add a content property.…However, for this property…I'm going to use the place holder type…and let's make it read-only.…
- Comparing object-oriented programming with protocol-oriented programming
- Methods and class-bound protocols
- Adopting a protocol
- Declaring asynchronous behavior
- Preparing and implementing fallback logic
- Implementing an app using protocol-oriented programming
Skill Level Intermediate
1. Protocol-Oriented Programming
4. Implement the Weather App Using POP
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.