Daily iOS
Swift

Large collections in structs

You need to put a very large Dictionary, hundreds of thousands of entries, into a struct property and pass that struct around by value. What's the 'fastest' way to store and pass it?

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

Dictionary is a COW container, so putting it in a struct and copying only shares the heap buffer and bumps a reference count (O(1)). Just store it and pass it by value.

Share a question