Daily iOS
Memory and ARC

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?

How would an interviewer hear this answer? You'll see whether they'd move on, dig in, or say no, and which sentences would trip you up. Your score doesn't change.
See the short answer

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.

Share a question