Shared references inside value types
A webtoon app's Episode struct has an ImageCache property of class type. If you copy the struct and change the cache on one side, what state is shared with the other?
A webtoon app's Episode struct has an ImageCache property of class type. If you copy the struct and change the cache on one side, what state is shared with the other?
The struct's other fields (values like id and title) become independent copies, but the ImageCache field only copies the pointer, so both Episodes point at the same ImageCache instance, and adding or clearing images on one side shows up on the other. A value type guarantees value semantics only as far as its own fields.
SwiftMultiple choiceIntro
What does this code print? …
#struct #class #value-semantics
Memory and ARCMultiple choiceIntro
Which statement about the stack and the heap is correct?
#struct #class
Memory and ARCShort answerBasics
In struct Order { var items: [Item]; let customer: Customer }, Item is a struct and…
#struct #class
CS fundamentals and algorithmsMultiple choiceAdvanced
You iterate over 100,000 coordinates and sum distances. Between these two versions…
#struct #class