Predict the output
What does this print?
struct PointS { var x = 0 }
final class PointC { var x = 0 }
var a = PointS()
var b = a
b.x = 5
let c = PointC()
let d = c
d.x = 5
print(a.x, c.x)Hint 1 of 1
Which assignment copies the data?
Choose an answer, then open Show answer below to check it.
Show answer
Answer: B 0 5
Correct. The struct was copied; the class instance is shared by c and d.
Why not the others?
- A 5 5.
bis a copy ofa, so changingbdoesn't affecta. - C 0 0. c and d point to the same object, so the change is visible through c.
- D It doesn't compile because d is a let.
letfixes the reference, not the object's properties.