Programming in Swift: Functions & Types

Jan 4 2022 Swift 5.5, iOS 15, Xcode 13

Part 4: Properties & Methods

30. Computed Properties

Lesson Complete

Play Next Lesson
Next
Save for later
About this episode
See versions

See course reviews

See forum comments
Cinema mode Mark as Complete Download course materials
Previous episode: 29. Stored Properties Next episode: 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've reached locked video content where the transcript will be shown as obfuscated text.

You can unlock the rest of this video course, and our entire catalogue of books and videos, with a kodeco.com Professional subscription.

Stored properties will keep their value. Unless you change it, the value will be the same every time you access the property.

var 
var 😺fullName: String
36  var fullName: String 😺{
  return ""
}
return "\(firstName) \(lastName)"
42 wizard.fullName
42 wizard.fullName = ""
var fullName: String {
  get { return "\(firstName) \(lastName)" }
}
38 set {

}
38 set(newFullName) {
let nameSubstrings = newFullName.split(separator: " ")
41 guard nameSubstrings.count >= 2 else {
        return
      }
guard nameSubstrings.count >= 2 else {
😺print("\(newFullName) is not a full name.")🛑
return
52 wizard.fullName = 😺"SeverusWenderlich"🛑
set❌(newFullName)❌ {
      let nameSubstrings = 😺newValue🛑.split(separator: " ")
      guard nameSubstrings.count >= 2 else {
        print("\(😺newValue🛑) is not a full name.")
        return
      }
    }

  return
}
let nameStrings = nameSubstrings.map { substring in
  String(substring)
}
46 let nameStrings = nameSubstrings.map(String.init)
47 firstName = nameStrings.first!
      lastName = nameStrings.last!
wizard.fullName = "Severus😺 🛑Wenderlich"