Protecting the original
You passed a class instance to a function, changed a property inside it, and the caller's original changed too. How do you protect the original?
You passed a class instance to a function, changed a property inside it, and the caller's original changed too. How do you protect the original?
A class is a reference type, so inside and outside the function see one object. To protect the original, model it as a value type like a struct, make a copy before passing it, or expose it through a read-only protocol.
Memory and ARCShort answerBasics
In struct Order { var items: [Item]; let customer: Customer }, Item is a struct and…
#deep-copy #shallow-copy #nscopying
SwiftMultiple choiceIntro
What does this code print? …
#value-semantics
SwiftShort answerBasics
Which line in this code fails to compile, and why? …
#value-semantics
SwiftShort answerExpert
You need a struct ImageBuffer that wraps a large pixel buffer, keeps value semantics, and…
#value-semantics