Junior — Senior
What will be the output? (Task #23)
livecode
Task condition
This example considers a structure with property observers. It is necessary to understand what will happen when attempting to change the property value inside its willSet and didSet, and what the final printed result will be.
struct MyStruct {
var value: Int {
willSet {
// Attempt to modify the property in willSet
self.value += 1
}
didSet {
// Attempt to modify the property in didSet
self.value += 100
}
}
}
var instance = MyStruct(value: 1000)
instance.value += 10
print(instance.value)
Determine what will be printed to the console after executing this code.