#11: Recursive Property Observers
Question
// Swift Quiz
— objc.io (@objcio) May 1, 2019
var quiz = ("iOS", "Quiz") {
didSet {
quiz.1 = "Swift"
}
}
quiz.0 = "Advanced"
// What's the value of quiz?
Solution
Solution: ("Advanced", "Swift")
— objc.io (@objcio) May 2, 2019
In Swift 5, when setting a property from within its own didSet or willSet observer, the observer will only avoid being recursively called if the property is set on self (either implicitly or explicitly).https://t.co/s7500CWmAg