Join Scott Gardner for an in-depth discussion in this video Constrain generic types, part of Swift 3 Essential Training: Beyond the Basics.
- [Instructor] Generic type parameters…can optionally be defined with type constraints…as you saw set in dictionary…due to required types that adopt the hashable protocol.…I'm starting out with an Edible protocol…that defines a couple properties.…A typealias for CustomStringConvertible called Describable,…an Ingredient struct that adopts and conforms…to Edible and CustomStringConvertible,…and I've also created several instances of Ingredient.…I've also started the definition of TrailMix,…which adopts and conforms to Describable.…I'll finish implementing TrailMix…and make it a generic structure.…
First, by defining TrailMix as a structure of type T…where T conforms to the Edible and Describable protocols.…These protocols will act as constraints on type T.…Type T can be of any type that adopts these protocols.…This is a change in Swift 3.…Previously, if you wanted to include a where clause…to further constrain the generic type,…you would have written it inside…the angle brackets where T is defined.…The where clause was moved to the end…
- Adding source files, resources, links, and literals
- Adding pages to a playground
- Using overflow operators and bitwise operators
- Using ranges with strings
- Creating complex sequences
- Chaining higher-order functions
- Defining lazy properties
- Using failable initializers
- Mutating methods
- Working with singletons
- Nesting function types
- Creating error types and recursive enumerations
- Extending concrete types
- Referencing selectors and key paths
- Working with protocol-oriented programming
- Defining class-only protocols and optional protocols
- Using option sets, type checking, and casting operators
Skill Level Intermediate
Core Data for iOS and macOS Enterprise Developerswith Jon Bott1h 46m Intermediate
Distributing Your iOS App for Testing with TestFlightwith Ron Buencamino35m 10s Intermediate
iOS App Development: Test-Driven Developmentwith Harrison Ferrone2h 14m Intermediate
3. Strings and Characters
4. Sequences and Collections
5. Control Flow
6. Value and Reference Types
9. Access Control
Understand access control3m 47s
Next steps1m 2s
- 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.