- [Narrator] We can also define a generic type that…adopts the anyrepresentable protocol.…I'm going to create a structure called GenericTagged.…This structure is going to be generic…so let's provide the placeholder type as usual.…And it conforms to Anyrepresentable.…I add the missing properties,…just copy and paste from our previous structure.…And for the content type, I'm going to set the type…to our T placeholder.…
Now, we can provide the type when creating an instance…of the structure.…So, let's create a constant called TaggedDouble…which is of type GenericTagged.…And we can provide type which is Double between…angled brackets and I'm going to initialize it…with a tag called pi and…assign it a value of Double dot pi.…
It could even delete the type because Swift's…type inference engine can figure out a type…based on the value we provide.…Now, we can also add type constraints to an…associated type in the protocol.…For example, we can restrict the content type to…types that conform to equatable.…Now, we must also enhance the generic tag structure…
- 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.