Generic types can work with any type. In this video, explore how to build a generic Box type.
- [Instructor] Generic types solve…a similar problem as generic functions.…Generic types can work with any type…and not only with the particular class,…structure, or enumeration.…This is why Swift's built in collection types:…the array, the set, and the dictionary…are implemented as generic collections.…Let's say that we need a wrapper that can hold values…of various types.…Strings, integers, dates, you name it.…I'm going to switch to another playground page…where we have some pre-defined structs.…
With a non-generic approach, we'd end up having a wrapper…for each type.…You've got a StringWrapper for string types,…an IntWrapper for integers,…and a DateWrapper for dates.…The number of dedicated wrapper types increases…with each new type that we need to support.…Besides, with every added type, we duplicate code.…The code becomes a maintenance nightmare.…Actually, even choosing the right wrapper…type is challenging.…Generics are here to help us.…
I'm going to remove these structs.…And let's start implementing our generic solution.…
- 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?
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.