Join Scott Gardner for an in-depth discussion in this video Define lazy properties, part of Swift 3 Essential Training: Beyond the Basics.
- [Teacher] Sometimes when working with types,…you'll want to delay initialization…of one or more properties until they are first accessed.…I'm starting out with a couple of imports.…Of foundation, in order to use the dispatch QAPI…to create a delay, and of playgroundsupport…in order to set this playground's page to continue…executing indefinitely, which is necessary when working…with delayed execution in a playground.…The delay for action function delays executing…the action closure parameter passed to it by…the for parameter.…
Next, I have the initial definition of a person struct,…which has first and last string properties…and a custom initializer.…And I've created an instance of person.…I'll add a created property to person.…This property will be set once as soon as…the instance of person is created.…To make this a lazy property so that the value…is not assigned until it's first accessed,…mark it with the lazy keyword.…I'm getting an error that lazy…cannot be used on a let.…
The fix it suggestion used to offer…
- 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.