Complete the code to declare a class named Person.
class [1] { var name: String init(name: String) { self.name = name } }
Complete the code to declare a strong reference property 'apartment' in Person class.
class Person { var name: String var [1]: Apartment? init(name: String) { self.name = name } }
Fix the error in the Apartment class to avoid a strong reference cycle by making the tenant reference weak.
class Apartment { let unit: String [1] var tenant: Person? init(unit: String) { self.unit = unit } }
Fill both blanks to complete the code that creates a strong reference cycle between Person and Apartment.
let john = Person(name: "John") let unit4A = Apartment(unit: "4A") john.[1] = unit4A unit4A.[2] = john
Fill all three blanks to complete the code that breaks the strong reference cycle using weak reference and optional chaining.
class Apartment { let unit: String [1] var tenant: Person? init(unit: String) { self.unit = unit } } let john = Person(name: "John") let unit4A = Apartment(unit: "4A") john.[2] = unit4A unit4A.tenant = john unit4A.tenant?.[3] = nil
