Autocoder

iOS and Swift Interview Questions and Answers

Last updated 2026-11-19

iOS interviews check three things: whether you understand Swift as a language, whether you can manage memory and concurrency without crashes or leaks, and whether you can build UI in SwiftUI while still reading UIKit code. Expect to explain value versus reference types, automatic reference counting and retain cycles, structured concurrency with async and await, and how SwiftUI decides to redraw a view.

The answers use current Swift, including the Observable macro, actors and the strict concurrency checking that Swift 6 enables. For comparison with other mobile stacks see the Android and Flutter pages. General process advice is in how to crack a pair programming interview.

LanguageSwift 5.9 and 6, SwiftUI, with UIKit background
Core topicsARC, value types, protocols, concurrency, SwiftUI state, lifecycle
Questions here17

Swift ideas that unlock many answers

Swift prefers value types: structs and enums are copied on assignment, and classes are shared by reference. Collections are value types with copy-on-write, so copying is cheap until you mutate. Protocols with extensions provide shared behaviour without inheritance. If you frame answers around those three ideas, the follow-ups on mutability, thread safety and testing become easy.

What changed recently

iOS and Swift Interview Questions and Answers: questions with worked answers

  1. 1

    What is the difference between a struct and a class in Swift?

    easy

    Structs are value types: assignment copies, there is no inheritance, and they get a memberwise initialiser. Classes are reference types: assignment shares one instance, they support inheritance, deinit and identity checks with ===. Prefer structs for models and use classes when you need shared mutable state or identity, such as a view model or a connection.

    swift
    struct Point { var x = 0 }
    var a = Point(); var b = a; b.x = 5      // a.x is still 0
    
    final class Counter { var n = 0 }
    let c1 = Counter(); let c2 = c1; c2.n = 5  // c1.n is 5
  2. 2

    How do optionals work and how should you unwrap them?

    easy

    An optional wraps either a value or nil. Unwrap safely with if let, guard let, optional chaining ?. or nil-coalescing ??. Force unwrapping with ! crashes on nil, so reserve it for cases that are truly guaranteed. guard let is best for early exit, because the unwrapped name stays in scope for the rest of the function.

    swift
    func greet(_ name: String?) -> String {
        guard let name, !name.isEmpty else { return "Hello, guest" }
        return "Hello, \(name)"
    }
  3. 3

    How does ARC work, and what is a retain cycle?

    medium

    Automatic Reference Counting increments a class instance's count for each strong reference and frees it when the count reaches zero. A retain cycle occurs when two objects, or an object and a closure, hold strong references to each other, so neither is freed. Break it with weak, which becomes nil when the object is freed, or unowned, which assumes the object outlives the reference. Value types do not take part in ARC cycles.

    swift
    final class Loader {
        var onDone: (() -> Void)?
        func start() {
            onDone = { [weak self] in
                guard let self else { return }
                self.finish()
            }
        }
        func finish() {}
    }
  4. 4

    When do closures need [weak self]?

    medium

    When a closure that is stored, escaping, outlives the call and captures self strongly while self also holds the closure, directly or indirectly. Non-escaping closures and short-lived tasks that finish quickly do not create a lasting cycle. In a Task, capture self weakly only if the task can outlive the object and you want the object freed first. Use unowned only when the lifetimes are guaranteed.

  5. 5

    Protocols, extensions and protocol-oriented programming?

    medium

    A protocol defines requirements, and types of any kind can conform, including structs and enums. Protocol extensions give default implementations, so behaviour is shared without a class hierarchy. Use associated types and generics with constraints for flexible APIs, and some or any keywords for opaque and existential types. Protocol-based dependencies are easy to replace with fakes in tests.

    swift
    protocol Pricing { var price: Decimal { get } }
    extension Pricing {
        var priceWithTax: Decimal { price * 1.18 }
    }
    struct Book: Pricing { let price: Decimal }
  6. 6

    Explain async and await, Task and structured concurrency.

    medium

    An async function can suspend without blocking a thread, and you call it with await. Task creates unstructured work, async let and TaskGroup run child tasks concurrently within the parent scope, so cancellation and errors propagate and children finish before the scope exits. Check Task.isCancelled or call try Task.checkCancellation in long loops.

    swift
    func loadProfile() async throws -> (User, [Post]) {
        async let user = api.user()
        async let posts = api.posts()
        return try await (user, posts)
    }
  7. 7

    What are actors and @MainActor?

    medium

    An actor protects its mutable state by letting only one task at a time run on it, and access from outside is asynchronous with await. This removes data races without manual locks. @MainActor isolates code to the main thread, which UI types such as SwiftUI views and view models should use. Types crossing actors must be Sendable, meaning safe to share.

    swift
    actor Cache {
        private var store: [String: Data] = [:]
        func get(_ key: String) -> Data? { store[key] }
        func set(_ key: String, _ data: Data) { store[key] = data }
    }
  8. 8

    Explain @State, @Binding and @Observable in SwiftUI.

    medium

    @State owns simple value state inside a view and survives redraws. @Binding is a two-way reference to state owned elsewhere, passed with a dollar prefix. With the Observable macro, mark a class @Observable and SwiftUI tracks which properties each view reads, redrawing only when those change. Own an @Observable object in a view with @State, and pass it down plainly or with @Bindable when you need bindings. Before iOS 17 the equivalents were ObservableObject with @StateObject and @ObservedObject.

    swift
    @Observable final class Counter { var count = 0 }
    
    struct CounterView: View {
        @State private var model = Counter()
        var body: some View {
            Button("Count: \(model.count)") { model.count += 1 }
        }
    }
  9. 9

    Why does SwiftUI recreate views so often, and why is that fine?

    medium

    SwiftUI views are lightweight structs that describe UI. The framework creates new values whenever state they depend on changes and diffs the result to update the real UI. So the body must be cheap and free of side effects. Put work in .task, onChange or a view model, and never do networking or heavy computation in body. Identity, given by position or id, decides whether state is kept.

  10. 10

    How do you handle errors in Swift?

    medium

    Functions marked throws signal failure, callers use try inside do and catch, or try? for an optional result, or try! to crash. Define errors as enums conforming to Error, with associated values. Typed throws arrived in Swift 6 for specific cases. Result captures success or failure as a value, useful for storing outcomes. Avoid catching everything silently.

    swift
    enum APIError: Error { case badStatus(Int), decoding }
    
    func fetch() async throws -> User {
        let (data, resp) = try await URLSession.shared.data(from: url)
        guard (resp as? HTTPURLResponse)?.statusCode == 200 else { throw APIError.badStatus(0) }
        return try JSONDecoder().decode(User.self, from: data)
    }
  11. 11

    How does Codable work?

    medium

    Conforming to Codable, meaning Encodable and Decodable, lets the compiler synthesise JSON encoding and decoding when all properties are Codable. Use CodingKeys to map different key names and set keyDecodingStrategy to convertFromSnakeCase for snake_case APIs. Implement init(from:) for custom shapes, and decode optionals for fields that may be missing.

  12. 12

    Explain the UIKit view controller lifecycle.

    medium

    init, loadView, viewDidLoad once when the view is loaded, viewWillAppear and viewDidAppear each time it is shown, viewWillDisappear and viewDidDisappear when it leaves, and deinit when released. viewDidLoad is for one-time setup, viewWillAppear for refreshing data, and layout-dependent work belongs in viewDidLayoutSubviews. Remove observers and invalidate timers when the screen goes away to avoid leaks.

  13. 13

    What is copy-on-write?

    medium

    Standard collections such as Array, Dictionary and String are value types but share storage after a copy. The buffer is duplicated only when one of the copies is mutated and storage is not uniquely referenced. This keeps copies cheap while preserving value semantics. Your own structs do not get it for free, so a struct holding a large array copies the reference cheaply, and the array itself is copy-on-write.

  14. 14

    What does Sendable mean and how does Swift 6 use it?

    hard

    Sendable marks types that are safe to pass between concurrency domains. Value types made of Sendable members, actors and immutable final classes qualify. In Swift 6 language mode the compiler reports data races as errors, such as capturing a non-Sendable class in a Task that runs elsewhere. Adopt it gradually: enable strict concurrency warnings first, isolate UI to the main actor, and use actors for shared state.

  15. 15

    GCD versus async and await: what replaces what?

    hard

    Grand Central Dispatch queues run closures on threads, and common bugs are deadlocks from sync on the same queue, thread explosion and unstructured callbacks. async and await gives structured, cancellable concurrency with compiler checks. New code should prefer Swift concurrency, using DispatchQueue only for interop with older APIs, and bridging callbacks with withCheckedThrowingContinuation.

    swift
    func legacyFetch() async throws -> Data {
        try await withCheckedThrowingContinuation { cont in
            old.fetch { result in cont.resume(with: result) }
        }
    }
  16. 16

    How do generics and associated types work together?

    hard

    Generics let a function or type work with any type that meets constraints, written with a where clause. A protocol with an associated type, such as Sequence with Element, defines a placeholder the conforming type fills in. Because such protocols are not usable as plain types in older code, you use generics or the some keyword for opaque returns, and any for existentials, which carry a runtime cost.

    swift
    func largest<S: Sequence>(_ items: S) -> S.Element? where S.Element: Comparable {
        items.max()
    }
  17. 17

    How do you persist data on iOS?

    hard

    Use UserDefaults only for small preferences, Keychain for secrets such as tokens, files for documents, and a database for structured data. SwiftData, available from iOS 17, offers model macros over a Core Data stack, and Core Data remains common in existing apps. SQLite libraries such as GRDB are an alternative. Plan migrations early, and sync with CloudKit if needed.

  18. 18

    How do you test and profile an iOS app?

    hard

    Use XCTest or the Swift Testing framework for unit tests, with protocol-based fakes for networking, and XCUITest for UI flows. Profile with Instruments: Time Profiler for CPU, Allocations and Leaks for memory, and the Hangs and SwiftUI tools for slow views. Use the Memory Graph debugger to find retain cycles, and test on real, older devices.

Frequently asked questions

Should I learn SwiftUI or UIKit for interviews?

Both. New work uses SwiftUI, but many production apps are UIKit or a mix, and interviewers often ask about view controller lifecycle and Auto Layout.

Do I need a Mac to prepare?

Practically yes, since Xcode runs only on macOS. You can still study the language and concepts without one.

What are the most common iOS interview topics?

ARC and retain cycles, optionals, value versus reference types, concurrency, SwiftUI state management and app architecture.

Is Objective-C still asked about?

Rarely for new roles, but you may need to read it in older codebases and bridge to Swift.

Related guides

More in Role-wise Interview Questions by Job and Tech Stack

See all in this section