Shallow vs deep copy
In struct Order { var items: [Item]; let customer: Customer }, Item is a struct and Customer is a class. After var copy = order, what happens to the original if you change copy.customer.name?
In struct Order { var items: [Item]; let customer: Customer }, Item is a struct and Customer is a class. After var copy = order, what happens to the original if you change copy.customer.name?
A struct copy copies the fields as they are, so a class property only copies the reference (a shallow copy) and the original's customer.name changes too. items is an array of structs, so it keeps value semantics.
SwiftShort answerBasics
You passed a class instance to a function, changed a property inside it, and the caller's…
#shallow-copy #deep-copy #nscopying
Memory and ARCMultiple choiceIntro
Which statement about the stack and the heap is correct?
#struct #class
Memory and ARCShort answerAdvanced
A webtoon app's Episode struct has an ImageCache property of class type. If you copy the…
#struct #class
CS fundamentals and algorithmsMultiple choiceAdvanced
You iterate over 100,000 coordinates and sum distances. Between these two versions…
#struct #class