← Snap Interview InsightsSoftware Engineer

Snap·Software Engineer·Technical Phone Screen·Intermediate

Intermediate
Jun 2026

Summary

Snapchat software engineer interview that leaned pretty hard into Swift fundamentals. One question, but it had a lot of surface area and I don't think I covered all of it as cleanly as I should have.

Questions Asked (1)

Q1

What are the key differences between class and struct in Swift? Think about things like how they handle memory, mutability, inheritance, and when you'd actually choose one over the other.

Technical Trade-offsSystem Design
Author's notes

I started with value vs reference semantics which was the right call, but then I kind of rambled through the rest without a clear order.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by defining the core semantic differences (reference vs. value types) and then systematically cover memory management, mutability, inheritance, and performance implications. Conclude with practical guidelines for choosing between them, emphasizing Swift's default preference for structs and the role of protocols. Use concrete examples to illustrate trade-offs.

Pro tip: Mention that Swift's standard library uses structs for fundamental types (e.g., Array, String, Dictionary) and that choosing structs by default leads to safer, more predictable code, especially in multithreaded environments like Snapchat's.

1. Define the core difference

Explain that classes are reference types (instances share a single copy) while structs are value types (each instance has its own copy). This fundamental distinction drives all other differences.

2. Cover memory and mutability

Describe how classes are allocated on the heap and managed via ARC, while structs are typically allocated on the stack (or inline) and copied on assignment. Discuss how mutability differs: struct methods that modify properties must be marked 'mutating', and constants of struct type are immutable.

3. Discuss inheritance and polymorphism

Highlight that classes support inheritance and can be subclassed, enabling polymorphism and shared behavior. Structs do not support inheritance but can conform to protocols, which is often sufficient for abstraction.

4. Explain performance and memory implications

Note that structs avoid heap allocation and reference counting overhead, leading to better performance in many cases. However, large structs can cause expensive copies, so use copy-on-write or classes when sharing is needed.

5. Provide decision guidelines

Give practical advice: use structs by default, especially for simple data models; use classes when you need identity, inheritance, or shared mutable state. Mention that protocols and generics often allow struct-based designs.

Key Points to Mention

  • Reference vs. value semantics: classes are passed by reference, structs by value.
  • Memory management: classes use ARC and heap allocation; structs are stack-allocated and copied.
  • Mutability: struct methods that modify state must be marked 'mutating'; class methods can modify freely.
  • Inheritance: classes support inheritance; structs do not but can conform to protocols.
  • Performance: structs avoid retain/release overhead but can be costly to copy if large.
  • Use cases: prefer structs for simple data, classes for shared mutable state or identity.

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.