Programming in Swift: Functions & Types

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

Part 4: Properties & Methods

29. Stored 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: 28. Introduction Next episode: 30. Computed 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: 29. Stored 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've reached locked video content where the transcript will be shown as obfuscated text.

In the Swift Fundamentals course, you created a Student struct that had several properties. The name, grade, and pet were all “stored properties”. They were also instance properties. Which means their values would be stored with the Student instance they belong to.

32 struct Wizard {

}
33 var firstName: String
   var lastName: String
let wizard = Wizard(firstName: "Gandalf", lastName: "Greyjoy")
wizard.firstName
wizard.lastName
😺var 🛑wizard = 
wizard.firstName = "Hermione"
wizard.lastName = "Kenobi"
wizard
var firstName: String 😺{

}
34  willSet {
     
    }
    didSet {
      
    }
print(firstName + " will be set to " + newValue)
if firstName.contains(" ") {

}
print("No spaces allowed! \(firstName) is not a first name. Reverting name to \(oldValue).")
firstName = oldValue
wizard.firstName = "Merlin Rincewind"
let commonMagicalIngredients = [
  "Polyjuice Potion",
  "Eye of Haystack Needle",
  "The Force"
]
😺static 🛑let commonMagicalIngredients = [
Wizard.commonMagicalIngredients
static var commonMagicalIngredients = [
Wizard.commonMagicalIngredients😺.append("Wow-Wow Sauce")
    "The Force"
]😺 {
  didSet {
    print("Magical Ingredients updated! Common stock now contains \(commonMagicalIngredients)")
  }
}🛑