Pick the fix
A CreditCard always belongs to a Customer and is destroyed with it. The card holds a reference back to its customer. Which declaration?
Hint 1 of 1
Can the card outlive the customer?
Choose an answer, then open Show answer below to check it.
Show answer
Answer: A unowned let customer: Customer
Correct. The customer always outlives the card, and the property can be non-optional.
Why not the others?
- B
weak var customer: Customer?. It is safe, but adds an optional for a reference that can never be nil while the card exists. - C
let customer: Customer(strong). Customer → card → customer is a retain cycle. - D
unowned(unsafe) let customer: Customer. It drops the safety check for no benefit.