Daily iOS
Swift

Value vs reference types

In Swift, what's the fundamental difference between a struct and a class?

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

A struct is a value type: it's copied on assignment and tends to live on the stack. A class is a reference type: it's shared by reference and managed by ARC. The dividing line is whether assignment and passing copy the value or point at one shared instance.

Share a question