iOS (Swift) Interview Questions and Answers
iOS and Swift interview questions with answers and code: value vs reference types, optionals, protocols, memory management and ARC, Swift concurrency, SwiftUI, UIKit, architecture, persistence and testing.
Key takeaways
- iOS interviews start with Swift fundamentals: value vs reference types, optionals, protocols and generics.
- ARC and retain cycles are asked at every level; know
weak,unownedand capture lists. - Swift concurrency (async/await, actors,
@MainActor) and SwiftUI state are now core topics. - Senior roles add architecture, modularization, performance and testing strategy.
Contents
iOS interviews test Swift fundamentals, memory management, concurrency and UI frameworks, plus architecture for larger apps. Below are 30 common questions grouped by topic and level, with code.
What iOS interviews cover
Editorial estimate.
- Swift language25%
- Memory and concurrency25%
- SwiftUI and UIKit20%
- Architecture and data15%
- Performance and testing15%
Weak vs unowned vs strong
| Reference | Increases count | Optional | If the object is gone | Typical use |
|---|---|---|---|---|
strong | ✓ | either | — | Ownership |
weak | ✓ | becomes nil | Delegates, [weak self] in closures | |
unowned | crash on access | Back-references with guaranteed lifetime |
See also Android (Kotlin) and system design interview questions.
Swift fundamentals
1Struct vs class in Swift?
JuniorStructs are value types: copied on assignment, no inheritance, thread-friendly. Classes are reference types with identity, inheritance and deinitializers, managed by ARC. Apple recommends structs by default and classes when you need identity or shared mutable state.
2What are optionals, and how do you unwrap them safely?
JuniorAn optional may hold a value or nil. Unwrap with if let, guard let, optional chaining (user?.address?.city) or the nil-coalescing operator (name ?? "Guest"). Force unwrapping with ! crashes on nil and should be rare.
3What is copy-on-write?
MidStandard collections like Array, Dictionary and String are value types, but they share storage until one copy is mutated, at which point the storage is copied. This gives value semantics without paying for a copy on every assignment.
4let vs var, and mutating methods?
Juniorlet declares a constant; for structs, the whole value becomes immutable. Methods that modify a struct’s properties must be marked mutating, since they replace self.
5What are enums with associated values used for?
MidModeling states with data, checked exhaustively by switch:
enum LoadState {
case idle
case loading
case loaded([Item])
case failed(Error)
}
6How does error handling work in Swift?
MidFunctions marked throws propagate errors that callers handle with do/catch, or convert with try? (to an optional) or try! (crash on error). Result<Success, Failure> represents outcomes as values, useful with callbacks.
Protocols and generics
7What is protocol-oriented programming?
MidDesigning with protocols and protocol extensions instead of class hierarchies. Value types can conform to many protocols, extensions provide default implementations, and code depends on abstractions, which makes testing easier.
8What is the difference between some and any?
Midsome Protocol is an opaque type: one specific concrete type chosen by the implementation, known to the compiler (used for SwiftUI’s some View). any Protocol is an existential: a box that can hold any conforming type, with some runtime cost and limitations.
9What are associated types in protocols?
MidPlaceholders for types that conforming types specify, such as Element in Collection. They make protocols generic, which is why such protocols are used with generics or some/any.
Get iOS (Swift) answer points in real time during your interview
Sottena listens to the interviewer, detects each question and shows short answer points in about a second. 150 free credits, no card required.
Memory management
10How does ARC work?
JuniorAutomatic Reference Counting counts strong references to each class instance and frees it when the count reaches zero. It’s deterministic, but it can’t break reference cycles on its own.
11What is a retain cycle, and how do you break it?
MidTwo objects holding strong references to each other (or an object and a closure capturing it) never reach a reference count of zero. Break cycles with weak or unowned references, typically for delegates and in closure capture lists:
service.load { [weak self] result in
guard let self else { return }
self.render(result)
}
12weak vs unowned?
MidBoth don’t increase the reference count. weak is optional and becomes nil when the object is deallocated. unowned is non-optional and assumes the object outlives the reference; accessing it after deallocation crashes. Use weak unless the lifetime guarantee is clear.
13How do you find memory leaks in an iOS app?
MidUse Xcode’s Memory Graph Debugger to find retain cycles, Instruments (Leaks, Allocations) for growth over time, and check that view controllers and view models are deallocated when screens close (a deinit log helps).
Concurrency
14How does async/await work in Swift?
Midasync functions can suspend at await points without blocking threads. Task { } starts asynchronous work from synchronous code, async let and task groups run work in parallel, and cancellation is cooperative through Task.isCancelled or try Task.checkCancellation().
15What is an actor?
MidA reference type that protects its mutable state by serializing access: only one task runs inside it at a time, and calls from outside are awaited. Actors prevent data races without manual locks.
16What does @MainActor do?
MidIt guarantees that code runs on the main thread, which is required for UI updates. Mark view models or UI-related types with @MainActor so the compiler enforces it.
17What is Sendable, and why does strict concurrency checking matter?
SeniorSendable marks types that are safe to share across concurrency domains (immutable values, actors, synchronized classes). With strict concurrency checking (the default in the Swift 6 language mode), the compiler reports data races at compile time, which forces explicit decisions about shared state.
18GCD vs Swift concurrency?
MidGrand Central Dispatch schedules closures on queues and is still used in older code. Swift concurrency adds structured tasks, cancellation, actors and compiler-checked safety, and is the preferred approach for new code.
SwiftUI and UIKit
19@State vs @Binding vs @Observable?
Mid@State stores view-local value state. @Binding gives a child read-write access to a parent’s state. With the Observation framework (iOS 17+), classes marked @Observable let views track exactly the properties they read; older code uses ObservableObject with @Published and @StateObject/@ObservedObject.
20Why are SwiftUI views structs, and what triggers updates?
MidViews are lightweight descriptions of UI, recreated often; SwiftUI compares them and updates the real UI. Changes to state that a view reads trigger re-evaluation of its body, so body should be cheap and free of side effects.
21Explain the UIViewController lifecycle.
JuniorloadView → viewDidLoad (one-time setup) → viewWillAppear → viewDidAppear → viewWillDisappear → viewDidDisappear. Layout updates happen in viewWillLayoutSubviews/viewDidLayoutSubviews.
22How do you use SwiftUI and UIKit together?
MidEmbed SwiftUI in UIKit with UIHostingController, and UIKit in SwiftUI with UIViewRepresentable or UIViewControllerRepresentable and a coordinator for delegates. Many apps migrate screen by screen this way.
23How do you keep scrolling smooth in long lists?
MidUse lazy containers (List, LazyVStack) or cell reuse in UICollectionView, load and decode images asynchronously with caching and downsampling, avoid heavy work on the main thread, and profile with the Time Profiler and Hitches instruments.
Architecture and data
24MVC vs MVVM vs other architectures?
MidUIKit’s MVC often leads to massive view controllers. MVVM moves presentation logic into view models that are easy to test and fits SwiftUI naturally. Larger apps may use coordinators for navigation, or unidirectional architectures such as TCA. Explain why you chose one.
25How do you do dependency injection in iOS apps?
MidPass dependencies through initializers using protocols, assemble them in a composition root, and use SwiftUI’s environment for app-wide services. This makes view models testable with fakes.
26Which persistence options do you use, and when?
MidUserDefaults for small preferences, Keychain for secrets and tokens, files for documents and caches, SwiftData or Core Data for structured local data with relationships, and SQLite libraries when you need full control.
27Write a network call with async/await and Codable.
Midstruct User: Decodable { let id: Int; let name: String }
func fetchUser(id: Int) async throws -> User {
let url = URL(string: "https://api.example.com/users/\(id)")!
let (data, response) = try await URLSession.shared.data(from: url)
guard (response as? HTTPURLResponse)?.statusCode == 200 else {
throw URLError(.badServerResponse)
}
return try JSONDecoder().decode(User.self, from: data)
}
Testing and release
28How do you test an iOS app?
MidUnit tests for view models and services with protocol-based fakes (XCTest or Swift Testing), async tests with await, snapshot tests for UI components, and a small set of XCUITest flows for critical paths. Run them in CI on every pull request.
29How do you improve app launch time?
MidMeasure with Instruments’ App Launch template, defer non-essential work after the first frame, avoid heavy work in application(_:didFinishLaunchingWithOptions:), reduce dynamic frameworks, and lazy-load modules and data.
30How do you ship features safely to millions of users?
SeniorFeature flags and remote configuration, phased releases in App Store Connect, crash and performance monitoring, backward-compatible API changes, and the ability to disable a feature remotely without a new release.
How to prepare
- Know value vs reference semanticsStructs, classes, copy-on-write and when to use each.
- Practice spotting retain cyclesClosures, delegates and capture lists, with Memory Graph.
- Learn Swift concurrency wellasync/await, task groups, actors, MainActor, Sendable.
- Build a small SwiftUI appList + detail, networking, persistence and tests.
- Prepare a performance storyLaunch time, scrolling or memory, with Instruments data.
Get answer points in real time during your interview
Sottena listens to the interviewer, detects each question and shows short answer points in about a second. 150 free credits, no card required.