Skip to content
All guides

Swift interview questions: what a senior round scores

By Mike Salari. Staff mobile engineer · 500+ technical interviews from the hiring side.

This page is for iOS engineers walking into a Swift language round at senior level. You get ten questions as they are asked out loud, what the interviewer writes down, what a strong answer covers, a follow-up chain where each push changes one condition, and the weak answer that ends the question early. Three of them come with short code you can type from memory.

Who this is for

Senior and staff iOS engineers, and mid-level engineers stepping up. You already know what a struct and an actor are. The gap at this level is precision: where each guarantee stops, and what you say when the interviewer leans on it.

A senior loop is rarely won on the first answer. It is won on the second, after the push. So for every question below, rehearse the follow-ups as hard as the opener.

A second set of Swift questions with spoken answers is in the Swift guide on Mobile Interview Room.

The questions

1. "Is a struct safe to share across threads?"

What is scored: whether you know value semantics are shallow.

A strong answer covers:

  • Context: a struct copies on assignment, so a copy cannot change under you. That removes a whole class of bugs.
  • The limit: value semantics only go as deep as the stored properties. A struct holding a class instance copies the reference, and both copies share that object.
  • Decision: treat a struct as safe to send only when every stored property is a value type or Sendable. The compiler checks this for Sendable conformance.
  • Failure mode: a "model" struct with a cache class inside, mutated from two tasks.
  • Evidence: a Thread Sanitizer report, or the compiler error you got when you tried to send it.

Follow-ups:

  • Now the struct holds a [String: NSMutableString]. Still safe?
  • Now it is captured by a closure with no capture list. Does the closure see later changes?
  • Now it is 2 KB and copied in a hot loop. What does that cost?

Weak answer: "Structs are thread-safe." It is the most common overclaim in this round, and the interviewer will hand you a struct with a reference inside to prove it.

2. "Write copy-on-write for your own type."

What is scored: whether you know copy-on-write is library behaviour you can build, not something every struct gets.

A strong answer covers:

  • Standard collections are structs pointing at shared heap storage. Assignment copies the small struct; the buffer is copied on the first mutation of shared storage.
  • For your own type: a class for storage, and a uniqueness check before every mutation.
  • Cost: the first mutation of a shared copy is O(n).
  • Apple's docs for isKnownUniquelyReferenced(_:) warn it is not a thread-safety tool. Call it only from mutating methods with proper synchronization.
Swift
final class Storage {
    var values: [Int]
    init(_ values: [Int]) { self.values = values }
}

struct Buffer {
    private var storage = Storage([])

    mutating func append(_ value: Int) {
        if !isKnownUniquelyReferenced(&storage) {
            storage = Storage(storage.values)
        }
        storage.values.append(value)
    }
}

Follow-ups:

  • Two threads call append on two copies at once. What can go wrong?
  • A weak reference also points at the storage. Does the check still return true?
  • When would you skip copy-on-write and just use a class?

Weak answer: "Swift does copy-on-write for all structs." It is false, and it shows you have only used the feature, never built it.

3. "You are writing a public function. When do you write some, when any, and when a generic?"

What is scored: an API decision, with cost and evolution named.

A strong answer covers:

  • some P in a parameter is sugar for a generic: one concrete type per call site, full static type information.
  • any P is an existential: a box that can hold different conforming types at runtime, with dynamic dispatch.
  • Order of preference: generic or some first; any only for a mixed collection or a stored property whose type changes over time.
  • Return position: some P keeps the concrete type out of your contract, so you can change it later without breaking callers.
  • Failure mode: any at a module boundary spreads. Every caller downstream ends up boxed too.

Follow-ups:

  • The protocol now has an associated type. What changes?
  • The function returns one of two concrete types. Would you erase, or return an enum?
  • This is a hot rendering path. What would you measure?

Weak answer: "any is the new way to write protocols." It names syntax and skips the cost.

4. "When do you write Equatable and Hashable by hand?"

What is scored: whether you keep the contract between the two.

A strong answer covers:

  • Synthesized conformance compares and hashes every stored property. That is usually right.
  • Hand-written: when identity is one field, such as a server id, and other fields can change.
  • The rule: values that are equal must produce the same hash. Hash only what == compares.
  • Failure mode: a diffable list where an item's title changes, and the item is treated as deleted and inserted because it is hashed by title.
Swift
struct User: Hashable {
    let id: UUID
    var name: String

    static func == (lhs: User, rhs: User) -> Bool { lhs.id == rhs.id }
    func hash(into hasher: inout Hasher) { hasher.combine(id) }
}

Follow-ups:

  • Now == compares id and name but the hash uses only id. Is that allowed?
  • Now the list must animate a rename. Is identity-only equality still right?

Weak answer: "I implement hashValue." That API is the legacy one; hash(into:) is the requirement.

5. "The feed has 200 items and one is malformed. What does the user see?"

What is scored: whether you treat decoding as a trust boundary with a failure policy.

A strong answer covers:

  • Context: synthesized Codable fails the whole array when one element fails. The screen goes blank.
  • Decision: decode each element on its own, keep the good ones, report the bad one.
  • Missing versus null: a Swift optional turns both into nil, and so does decodeIfPresent. If the product needs the difference, check contains(_:) and then decodeNil(forKey:).
  • Do not mix .convertFromSnakeCase with hand-written snake_case CodingKeys. The strategy converts keys first, so your keys stop matching.
  • Evidence: a test per failure shape, using fixtures recorded from the real API.
Swift
struct Lossy<Element: Decodable>: Decodable {
    let elements: [Element]

    init(from decoder: Decoder) throws {
        var container = try decoder.unkeyedContainer()
        var result: [Element] = []
        while !container.isAtEnd {
            if let element = try? container.decode(Element.self) {
                result.append(element)
            } else {
                _ = try container.decode(Skip.self) // move past the bad element
            }
        }
        elements = result
    }

    private struct Skip: Decodable {
        init(from decoder: Decoder) throws {}
    }
}

Follow-ups:

  • Who decides whether a bad row is hidden or shown as an error?
  • Someone renames a property on the domain model. What happens to the wire format?

Weak answer: "I make the property optional." It erases the difference between missing and null, and often that difference is the requirement.

6. "weak or unowned, precisely?"

What is scored: choosing by lifetime, and knowing what a capture list does.

A strong answer covers:

  • The Swift book's rule: weak when the other instance can have a shorter lifetime, unowned when it has the same or a longer one.
  • weak is an optional var that becomes nil. Reading an unowned reference after deallocation is a runtime error.
  • A capture list is evaluated when the closure is created. Capturing a value there takes a snapshot; without it, the closure reads the variable later.
Swift
var count = 0
let live = { print(count) }
let snapshot = { [count] in print(count) }
count = 5
live()      // 5
snapshot()  // 0

Follow-ups:

  • Now the closure is non-escaping. Do you still need [weak self]?
  • Now the owner is a Task stored on the view model. Who cancels it?

Weak answer: "I put [weak self] everywhere." It is a habit, with no reasoning about who outlives whom.

7. "Would you use typed throws on your networking module's public API?"

What is scored: API evolution, not syntax.

A strong answer covers:

  • Swift 6 added typed throws, written throws(ParseError). A plain throws means throws(any Error), and a non-throwing function is throws(Never).
  • Where it fits: a closed error set, such as a parser, and generic code that forwards errors.
  • Where it hurts: at a public module boundary, the error enum becomes contract. Adding a case breaks every caller that switches over it.
  • Keep transport errors inside. If URLError escapes your module, your implementation is now your API.

Follow-ups:

  • Next quarter you add a rate-limit case. Who breaks?
  • The function is now generic over a closure that throws. Does typed throws help here?

Weak answer: "Typed throws is strictly better." It makes every new failure a breaking change.

8. "What does Sendable mean, and when is @unchecked acceptable?"

What is scored: whether you take the safety contract seriously.

A strong answer covers:

  • Sendable says a value is safe to cross isolation boundaries. Structs and enums of Sendable members, and actors, get it naturally.
  • A mutable class is the hard case. @unchecked Sendable means "I guarantee this by hand", so you own the proof.
  • Prefer a value type or an actor. Where you need a lock, Mutex from the Synchronization library is itself Sendable, so the class can conform without @unchecked. It needs iOS 18 or later.
Swift
import Synchronization

final class Counter: Sendable {
    private let count = Mutex(0)

    func increment() {
        count.withLock { $0 += 1 }
    }
}

Follow-ups:

  • Your deployment target is iOS 17. What now?
  • A third-party type you depend on is not Sendable. What are your options?

Weak answer: "I add @unchecked Sendable to make the warning go away." It silences the compiler and leaves the race.

9. "The user leaves the screen. Why is the work still running?"

What is scored: knowing cancellation is cooperative.

A strong answer covers:

  • cancel() sets a flag and cancels child tasks. It does not stop your code.
  • Your own loops must call try Task.checkCancellation() or read Task.isCancelled.
  • Let CancellationError propagate. A generic catch that swallows it hides the cancel from the caller.
  • For callback APIs, withTaskCancellationHandler tears down the resource the moment cancel arrives.
Swift
func processAll(_ items: [Item]) async throws {
    for item in items {
        try Task.checkCancellation()
        await process(item)
    }
}

Follow-ups:

  • Now process is a synchronous CPU loop of 10,000 iterations. Where do you check?
  • Now the task was started with Task { } and nobody stored it. Who can cancel it?

Weak answer: "I call cancel() and the task stops." The interviewer will ask why it kept running.

10. "What did Swift 6 change, and what did it not?"

What is scored: stating the guarantee and its boundary in one breath.

A strong answer covers:

  • Swift 6 added an opt-in language mode where possible data races are compile-time errors.
  • It catches unsafe sharing around actors and Sendable. It does not remove logic races across an await, deadlocks, or cancellation bugs.
  • Migration: stay in Swift 5 mode, enable checks per module, fix with the smallest true annotation, and keep a list of every unsafe opt-out.
  • Swift 6.2 added an option to isolate code to the main actor by default, plus @concurrent for work that should run off it.

Follow-ups:

  • "So data races are gone?" Walk it back to the precise version.
  • Which module would you migrate first, and why?

Weak answer: "Swift 6 guarantees data-race safety." One overclaim makes the interviewer doubt the rest of your answers.

What changed in 2024 to 2026

  • Swift 6, 17 September 2024: opt-in language mode that reports possible data races as compiler errors; typed throws, where a non-throwing function equals throws(Never); a Synchronization library with Atomic and a new mutex API; Swift Testing. (Announcing Swift 6)
  • Mutex in the Synchronization library is Sendable and requires iOS 18 or later. (Apple Developer: Mutex)
  • Swift 6.2, 15 September 2025: an option to isolate code to the main actor by default (-default-isolation MainActor), and the @concurrent attribute. (Swift 6.2 Released)
  • Swift 6.2 upcoming feature: nonisolated async functions run in the caller's execution context. It is opt-in. (Swift 6.2 Released)

Say which compiler and language mode your project uses before you lean on any of this.

How the rounds run

Formats vary by company and level. Some loops have a dedicated Swift round; others fold language questions into live coding or a project deep dive. No large company publishes a fixed iOS loop on an official page, so treat loops you read about online as one person's report. Ask the recruiter what each round scores and whether you will write Swift in Xcode or in a shared editor.

For the SwiftUI side of the same loop, read the SwiftUI interview questions guide. For senior judgement questions beyond the language, read senior iOS interview questions.

Sources