Junior — Senior
What will be output in example №30
livecode
Task condition
In this exercise, you need to predict the output of a program working with optional references to a class object. Analyze how the state of objects changes and what values will be accessible through optional chaining.
import Foundation
class Dog {
var name: String
init(name: String) {
self.name = name
}
}
var dog1: Dog? = Dog(name: "Buddy")
var dog2: Dog? = dog1
dog1?.name = "Buddy1"
print(dog2?.name ?? "nil")
Determine what value will be printed to the console when this code is executed.