PracHub
QuestionsPremiumLearningGuidesInterview PrepCoaches
|Home/Software Engineering Fundamentals/Snapchat

Explain Swift memory, value semantics, and GCD

Last updated: Mar 29, 2026

Quick Overview

This question evaluates a candidate's understanding of Swift memory management, value versus reference semantics, copy-on-write behavior, ARC stack vs heap distinctions, ownership qualifiers (weak vs unowned), and Grand Central Dispatch concurrency and execution order.

  • hard
  • Snapchat
  • Software Engineering Fundamentals
  • Software Engineer

Explain Swift memory, value semantics, and GCD

Company: Snapchat

Role: Software Engineer

Category: Software Engineering Fundamentals

Difficulty: hard

Interview Round: Onsite

Answer the following Swift/iOS fundamentals questions. ## A) GCD execution order + threads Assume the current thread is the **main thread**. ### Snippet 1 What is the output order? Which thread executes each `print`? ```swift let queue = DispatchQueue(label: "test") queue.async { print(1) } queue.sync { print(2) } print(3) ``` ### Snippet 2 What is the output order and why? ```swift var str = "1" DispatchQueue.main.async { str += "2" print(str) } DispatchQueue.main.async { str += "3" print(str) } print(str) ``` Also explain why the second async block prints `"123"` rather than `"13"`. ## B) Swift/iOS conceptual questions 1. Compare `class` vs `struct` in Swift (semantics, performance, common use cases). 2. What is copy-on-write (CoW) in Swift? How would you implement CoW behavior for a custom type? 3. Explain stack vs heap in the context of Swift/ARC and what actually “goes where.” 4. Compare `weak` vs `unowned`. Why can `unowned` crash while `weak` typically doesn’t?

Quick Answer: This question evaluates a candidate's understanding of Swift memory management, value versus reference semantics, copy-on-write behavior, ARC stack vs heap distinctions, ownership qualifiers (weak vs unowned), and Grand Central Dispatch concurrency and execution order.

Related Interview Questions

  • Compare WebSocket, SSE, and long polling - Snapchat (hard)
  • Implement an iOS scrollable grid with navigation - Snapchat (hard)
Snapchat logo
Snapchat
Jan 2, 2026, 12:00 AM
Software Engineer
Onsite
Software Engineering Fundamentals
2
0
Loading...

Answer the following Swift/iOS fundamentals questions.

A) GCD execution order + threads

Assume the current thread is the main thread.

Snippet 1

What is the output order? Which thread executes each print?

let queue = DispatchQueue(label: "test")
queue.async {
    print(1)
}
queue.sync {
    print(2)
}
print(3)

Snippet 2

What is the output order and why?

var str = "1"
DispatchQueue.main.async {
    str += "2"
    print(str)
}
DispatchQueue.main.async {
    str += "3"
    print(str)
}
print(str)

Also explain why the second async block prints "123" rather than "13".

B) Swift/iOS conceptual questions

  1. Compare class vs struct in Swift (semantics, performance, common use cases).
  2. What is copy-on-write (CoW) in Swift? How would you implement CoW behavior for a custom type?
  3. Explain stack vs heap in the context of Swift/ARC and what actually “goes where.”
  4. Compare weak vs unowned . Why can unowned crash while weak typically doesn’t?

Solution

Show

Comments (0)

Sign in to leave a comment

Loading comments...

Browse More Questions

More Software Engineering Fundamentals•More Snapchat•More Software Engineer•Snapchat Software Engineer•Snapchat Software Engineering Fundamentals•Software Engineer Software Engineering Fundamentals
PracHub

Master your tech interviews with 7,500+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.