Topic

Swift interview questions

Core language concepts, ownership, protocols, generics, concurrency, and the details interviewers use to separate memorization from real understanding.

Focus areas: Ownership, protocols, generics, concurrency, and language fundamentals

How much data can UserDefaults store, and how does it work on disk?

Explain UserDefaults as a small plist-backed prefs store covering size limits, async disk writes, suiteName vs standard, and why main-thread access is allowed but not free

How does Swift's Dictionary work under the hood?

Walk through Swift Dictionary as a CoW hash table — hashing invariants, collisions, complexity traps, nil removal, ordering, concurrency, and key design for senior interviews

How does Swift method dispatch work?

Explain Swift's three method-dispatch mechanisms—static, table (vtable and protocol witness tables), and Objective-C message send—and show when final, value types, and @objc dynamic change which one the compiler uses

What is the difference between NSCache and Dictionary?

Compare Dictionary and NSCache on one concrete example, an image cache for a photo feed, and show where the two diverge on thread safety, automatic eviction, and key and value rules

What is the difference between let and var in Swift?

Explain that let creates an immutable binding while var creates a mutable one, then separate how that rule behaves for value types versus reference types

How would you demonstrate Copy-on-Write behavior with a custom struct?

Demonstrate Copy-on-Write with a value-typed linked list that shares storage on assignment and copies it only when a mutation occurs using isKnownUniquelyReferenced.

What is a closure in Swift?

A closure is a block of code you can pass and store like a value, and it can capture constants and variables from the surrounding scope

What's the difference between strong, weak, and unowned references?

Under ARC, strong keeps an object alive, unowned tracks a direct non-owning pointer that must outlive use, and weak goes through a side table so access can become nil after deinit

What collection types are available in Swift, and when would you use each one?

Explain Swift's protocol-driven collection model, then compare Array, Set, Dictionary, and Range by behavior, complexity, hashing, ordering, copy-on-write, and thread-safety tradeoffs

Which design patterns have you used in iOS, and what tradeoffs did they have?

Group design patterns into creational, structural, and behavioral, then explain real iOS examples from SDKs and your own implementation experience with the tradeoffs that matter in production

What is the difference between print and debugPrint in Swift?

Explain that print prefers a user-facing string while debugPrint prefers a debug representation, then show when their output is identical and when it diverges

What is a retain cycle and how do you avoid it?

Define retain cycles in ARC terms, show the most common ways teams create them, and explain how to prevent and debug them in production code

How does struct memory layout work in Swift?

Explain MemoryLayout, padding, alignment, and stride; show why stored-property order changes a struct's footprint; and connect it to arrays, performance, and low-level interop