Swift basics
Language questions asked to almost every iOS candidate.
Q1.What is an optional in Swift?
An optional is a type that can hold a value or nil, written as String?. It forces you to deal with missing values at compile time instead of crashing at runtime.
Q2.What are the ways to unwrap an optional?
if let and guard let for safe binding, optional chaining with ?., the nil-coalescing operator ?? for a default value, and force unwrapping with !, which crashes if the value is nil and should be rare.
Q3.What is the difference between let and var?
let declares a constant that cannot be reassigned, var declares a variable. For a struct declared with let, none of its properties can change either. Prefer let by default.
Q4.What is the difference between a struct and a class?
Structs are value types: assigning or passing one makes a copy. Classes are reference types: copies share the same instance. Classes support inheritance and deinitializers and are managed by ARC. Swift encourages structs for models because copies are predictable and thread-safe.
Q5.What is copy-on-write?
Standard collections like Array and Dictionary are value types but do not copy their storage until one copy is modified. This gives value semantics without paying for a copy on every assignment.
Q6.What is an enum with associated values?
Each case can carry its own data, for example case success(Data) and case failure(Error). Combined with switch statements it models states cleanly, and the compiler checks that every case is handled.
Q7.What is a protocol?
A protocol defines a set of methods and properties a type must provide. Classes, structs and enums can all conform. Protocols are the base of Swift's protocol-oriented style and of most dependency injection and testing on iOS.
Q8.What is a protocol extension?
It adds default implementations to a protocol, so every conforming type gets the behaviour without writing it. It is how Swift shares behaviour without class inheritance.
Q9.What is the difference between some and any?
some Protocol is an opaque type: one specific concrete type that the compiler knows but hides from the caller, as in some View. any Protocol is an existential box that can hold any conforming type at runtime, with a small performance cost and fewer capabilities.
Q10.What are generics?
Generics let you write code that works with any type while staying type-safe, such as func first<T>(_ items: [T]) -> T?. Array, Dictionary and Result are all generic.
Q11.What is a closure?
A closure is a block of code that can be passed around and that captures variables from its surrounding scope. Swift functions and trailing closure syntax make them common for callbacks, sorting and SwiftUI views.
Q12.What is the difference between escaping and non-escaping closures?
A non-escaping closure runs before the function returns, which is the default. An @escaping closure is stored or called later, such as a completion handler, so it can create retain cycles and needs explicit self handling.
Q13.How does error handling work in Swift?
Functions marked throws can throw values conforming to Error. Callers use try inside do/catch, or try? to turn the result into an optional, or try! to crash on error. Swift 6 also supports typed throws.
Q14.What is Codable?
Codable combines Encodable and Decodable. The compiler generates code to convert types to and from JSON or property lists, and CodingKeys lets you map different key names.
Q15.What is the difference between map, compactMap and flatMap?
map transforms each element. compactMap transforms and drops nil results, so it is handy for turning strings into optional numbers. flatMap transforms each element into a sequence and flattens the results into one array.
Q16.What are property wrappers?
A property wrapper moves repeated get and set logic into a reusable type, marked with @propertyWrapper. SwiftUI's @State and @Binding are property wrappers, and you can write your own, for example to clamp a value or read from UserDefaults.
Q17.What does the defer statement do?
Code in a defer block runs when the current scope exits, however it exits, including through a thrown error or an early return. It is used for cleanup such as closing a file or unlocking a lock.
Memory and UIKit
Questions on ARC, lifecycle and the classic UI framework.
Q18.How does ARC work?
Automatic Reference Counting keeps a count of strong references to each class instance. When the count reaches zero, the instance is deallocated. It happens at compile time, not with a garbage collector.
Q19.What is a retain cycle and how do you break it?
Two objects hold strong references to each other, so neither count reaches zero. A common example is a closure stored on self that captures self. Break it with [weak self] or [unowned self] in the capture list, or make one of the properties weak.
Q20.What is the difference between weak and unowned?
Both avoid increasing the retain count. A weak reference is optional and becomes nil when the object is freed. An unowned reference is non-optional and crashes if accessed after the object is gone, so use it only when the other object always outlives it.
Q21.Describe the UIViewController lifecycle.
loadView, viewDidLoad once after the view loads, then viewWillAppear, viewIsAppearing, viewDidAppear each time it shows, and viewWillDisappear and viewDidDisappear when it leaves. Layout passes call viewWillLayoutSubviews and viewDidLayoutSubviews.
Q22.What is the difference between frame and bounds?
Frame is the view's position and size in its superview's coordinate system. Bounds is the view's own coordinate system, usually starting at zero, and changing its origin scrolls the content, which is how UIScrollView works.
Q23.What is Auto Layout?
A constraint-based system that calculates view sizes and positions from rules such as leading equals superview leading plus 16. It adapts to different screens, rotations and Dynamic Type. Content hugging and compression resistance priorities decide which view stretches or shrinks.
Q24.How does cell reuse work in UITableView and UICollectionView?
Only visible cells exist. When a cell scrolls off screen it goes into a reuse queue and is configured again for new data. You must reset any state in prepareForReuse or the configuration code, or old images and text appear in the wrong rows.
Q25.What is a diffable data source?
It lets you describe the list as a snapshot of sections and item identifiers. UIKit calculates the differences and animates inserts, deletes and moves for you, which avoids the classic crash from mismatched counts.
Q26.What are delegation and notifications, and when do you use each?
Delegation is one-to-one communication through a protocol, such as a table view asking its delegate for row heights. NotificationCenter is one-to-many broadcasting. Delegation is easier to follow, so use notifications only for truly global events.
Q27.What is the responder chain?
It is the chain of objects that can handle events, from the touched view up through superviews, view controllers, the window and the application. An event not handled by one responder moves to the next.
SwiftUI and concurrency
Modern iOS questions that are now standard in interviews.
Q28.How is SwiftUI different from UIKit?
SwiftUI is declarative: you describe what the UI should look like for a given state and the framework updates it when state changes. UIKit is imperative: you create views and change them yourself. SwiftUI views are lightweight structs rebuilt often.
Q29.What are @State and @Binding?
@State is private state owned by a view. @Binding is a two-way reference to state owned by a parent, so a child like a toggle can change it.
Q30.What does the Observation framework and @Observable change?
Since iOS 17 you mark a model class with @Observable and SwiftUI tracks exactly which properties a view reads, so only those views update. It replaces most uses of ObservableObject, @Published and @ObservedObject, and you own it in a view with @State.
Q31.What is the difference between @StateObject and @ObservedObject?
With ObservableObject, @StateObject creates and owns the object so it survives view rebuilds, while @ObservedObject only watches an object owned elsewhere. Creating a model with @ObservedObject inside a view is a classic bug because it gets recreated.
Q32.What is @Environment used for?
It reads values passed down the view tree, such as colour scheme, locale, dismiss actions or your own shared models, without passing them through every initialiser.
Q33.How do you navigate in SwiftUI?
Use NavigationStack with a path and navigationDestination(for:) for value-based navigation, which supports deep links and programmatic pushes. Sheets and full-screen covers handle modal flows.
Q34.How do you use UIKit inside SwiftUI and the other way round?
Wrap UIKit views with UIViewRepresentable or UIViewControllerRepresentable, using a Coordinator for delegates. Put SwiftUI inside UIKit with UIHostingController.
Q35.How do async and await work in Swift?
An async function can suspend without blocking a thread. You call it with await, and the code reads top to bottom like synchronous code. Work is started from a Task, and SwiftUI's .task modifier ties a task to a view's lifetime.
Q36.What is an actor?
An actor is a reference type that protects its mutable state by allowing only one task at a time to access it. Calls from outside need await. It removes most data races without manual locks.
Q37.What is @MainActor?
It is a global actor that runs code on the main thread. Marking a ViewModel or function with it guarantees UI updates happen on the main thread, and the compiler enforces it.
Q38.What is Sendable and why does Swift 6 care about it?
Sendable marks types that are safe to share across concurrency domains, such as value types with Sendable properties or actors. The Swift 6 language mode turns data race checks into errors, so non-Sendable values crossing actor boundaries no longer compile.
Q39.What is the difference between Task, TaskGroup and async let?
async let starts a fixed number of child tasks in parallel. A TaskGroup handles a dynamic number of child tasks. Task {} creates a new top-level unit of work that inherits the actor context, and Task.detached does not inherit it.
Q40.How does task cancellation work?
Cancellation is cooperative. Cancelling a task sets a flag, and your code must check Task.isCancelled or call try Task.checkCancellation(). Many system APIs such as URLSession throw CancellationError automatically.
Q41.What are Swift macros?
Macros generate code at compile time. Freestanding macros like #Preview and #expect produce expressions, and attached macros like @Observable and @Model add members or conformances to a type. Unlike C macros they are type-checked and you can expand them in Xcode to see the generated code.
Data, tooling and release
Persistence, testing and shipping questions.
Q42.What is Core Data, and how is SwiftData different?
Core Data is Apple's object graph and persistence framework, usually backed by SQLite. SwiftData, from iOS 17, defines models in Swift code with the @Model macro and plugs into SwiftUI with @Query. By default it stores data in a SQLite store, and it can share a store with an existing Core Data stack during migration.
Q43.How do you make a network request in Swift?
Use URLSession with async/await: let (data, response) = try await URLSession.shared.data(from: url), check the HTTP status code and decode with JSONDecoder. Wrap it in an API client protocol so it can be mocked in tests.
Q44.How do you store sensitive data?
Use the Keychain for tokens and passwords, never UserDefaults. Mark files with data protection classes, and avoid logging personal data.
Q45.How do you write unit tests on iOS?
Use XCTest or the newer Swift Testing framework with @Test and #expect. Inject dependencies through protocols so you can mock network and storage, and test ViewModels and logic rather than views.
Q46.Which Instruments do you use most?
Time Profiler for CPU, Allocations and Leaks for memory, the SwiftUI and Hangs instruments for UI stalls, Network for traffic and Energy Log for battery problems.
Q47.What is the difference between a certificate and a provisioning profile?
The certificate proves the developer's identity and signs the binary. The provisioning profile ties together the app ID, certificates, allowed devices for development builds and entitlements such as push notifications.
Q48.How do Swift Package Manager and CocoaPods differ?
SwiftPM is Apple's built-in dependency manager integrated into Xcode. CocoaPods is an older third-party tool that changes the Xcode workspace. CocoaPods trunk is moving to read-only, so new projects should use SwiftPM.
Q49.What happens during App Store review and how do you avoid rejection?
Apple checks the app against the App Review Guidelines. Common rejections are crashes, incomplete metadata, missing privacy explanations, hidden features, payments for digital goods outside in-app purchase in regions where that applies, and missing account deletion. Provide a demo account and clear review notes.
Q50.You found a retain cycle between a ViewModel and a closure. How do you confirm and fix it?
Confirm with the memory graph debugger or by adding a deinit print that never fires. Then add [weak self] to the closure capture list, or cancel the subscription or task when the view disappears, and check that deinit now runs.
Q51.A SwiftUI list stutters while scrolling. What do you check?
Expensive work in body, views without stable identifiers, images decoded at full size on the main thread, too many observable properties causing wide updates, and GeometryReader inside each row. Use the SwiftUI instrument to see which views update.
Q52.How would you support offline mode in an iOS app?
Persist data with SwiftData, Core Data or SQLite and show it immediately, refresh from the network in the background, watch connectivity with NWPathMonitor, and queue changes made offline so they sync when the connection returns.
How to prepare for the interview
- Expect a live Swift exercise: parsing JSON with Codable, filtering an array or fixing a retain cycle.
- Know both UIKit and SwiftUI. Many codebases mix them, so interop questions are common.
- Be able to explain one bug you fixed with Instruments.
- Read the Swift concurrency rules for your Swift version, since strict checking changed what compiles.