Programming in Swift: Functions & Types

Jan 4 2022 · Swift 5.5, iOS 15, Xcode 13

Part 4: Properties & Methods

31. Lazy Properties

Episode complete

Play next episode

Next
About this episode

Leave a rating/review

See forum comments
Cinema mode Mark complete Download course materials
Previous episode: 30. Computed Properties Next episode: 32. Challenge: Properties

Get immediate access to this and 4,000+ other videos and books.

Take your career further with a Kodeco Personal Plan. With unlimited access to over 40+ books and 4,000+ professional videos in a single subscription, it's simply the best investment you can make in your development career.

Learn more Already a subscriber? Sign in.

Notes: 31. Lazy Properties

Update Notes: This course was originally recorded in 2019. It has been reviewed and all content and materials updated as of October 2021.

Heads up... You’re accessing parts of this content for free, with some sections shown as obfuscated text.

Heads up... You’re accessing parts of this content for free, with some sections shown as obfuscated text.

Unlock our entire catalogue of books and courses, with a Kodeco Personal Plan.

Unlock now

We’re back with our Wizard struct, and there’s one last thing I’d like to show you, that you can do with instance variables. Let’s say we want to add another stored property, like magicalCreature, and just for a moment, assign it an empty String

63 var magicalCreature = ""
63 lazy var magicalCreature = ""
63   lazy var magicalCreature = summonMagicalCreature(summoner: fullName)
var wizard = Wizard(firstName: "Gandalf", lastName: "Greyjoy")
😺Wizard(firstName: <#T##String#>, lastName: <#T##String#>, magicalCreature: <#T##String?#>)🛑
var wizard = Wizard(firstName: "Gandalf", lastName: "Greyjoy")
❌Wizard(firstName: <#T##String#>, lastName: <#T##String#>, magicalCreature: <#T##String?#>)❌
65 init(firstName: String, lastName: String) {
    
  }
66 self.firstName = firstName
self.lastName = lastName
print(wizard.magicalCreature)
wizard.fullName = "Qui-Gon Crayskull"
print(wizard.magicalCreature)