Programming in Swift: Functions & Types

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

Part 4: Properties & Methods

30. Computed 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: 29. Stored Properties Next episode: 31. Lazy 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: 30. Computed 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

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"