Real-world interview practice

Swift Interview Scenarios: 8 Real-World Problems and How to Answer Them

Explain how Swift language features and platform tools help you build responsive, safe, and maintainable apps.

Swift concurrency Memory and performance Networking App reliability

How to approach scenario questions

Interviewers want to hear how you investigate constraints, make trade-offs, and verify a solution. Use each problem to explain a practical decision process, not just name a language feature.

A clear answer structure

  1. Clarify requirements and failure conditions.
  2. Explain the approach and why it fits.
  3. Cover trade-offs, safety, and edge cases.
  4. Describe how you would test and measure it.
Real-world problem 1

Search results are overwritten by an older request. How would you handle the race?

The scenario

A user types several queries quickly and the network responds to them out of order.

A strong answer

Cancel the previous Task when a new query begins and verify that the result still belongs to the latest query before updating the UI. Debounce requests to reduce traffic, propagate cancellation to the networking layer, and update UI state on the main actor.

Real-world problem 2

A shared token refresh can run concurrently in several screens. How would you prevent duplicate refreshes?

The scenario

Multiple requests discover an expired token at once and start separate refresh calls.

A strong answer

Isolate refresh state in an actor or another serialized owner and let concurrent callers await the same in-flight refresh. Store the resulting token atomically, handle refresh failure consistently, and ensure canceled callers do not leave shared state stuck.

Real-world problem 3

A scrolling list uses too much memory for images. What would you change?

The scenario

The app loads full-resolution images for every row and memory rises as the user scrolls.

A strong answer

Load images lazily, downsample to the rendered size, and use a bounded cache with a suitable eviction policy. Cancel work for reused or off-screen rows and avoid retaining decoded images longer than needed. Profile memory while scrolling a realistic list.

Real-world problem 4

A view controller or view model stays in memory after dismissal. How would you investigate?

The scenario

Memory graphs show the screen remains retained after navigation away.

A strong answer

Inspect the ownership graph for strong reference cycles, especially closures capturing self, delegates, timers, and long-lived tasks. Use weak captures where ownership should not be retained, cancel tasks when appropriate, and verify deallocation with a repeatable navigation test.

Real-world problem 5

A screen keeps doing network work after the user leaves. What is the Swift concurrency fix?

The scenario

An unstructured Task continues after its screen has disappeared and updates stale state.

A strong answer

Tie work to an explicit owner, cancel the task when the screen or feature ends, and check cancellation before expensive follow-up work. Prefer structured concurrency and propagate cancellation through child tasks and network calls.

Real-world problem 6

An API sometimes omits fields or sends invalid values. How should a Decodable model respond?

The scenario

A decoding failure prevents an entire screen from loading even though some fields are optional.

A strong answer

Model truly optional fields as optional and keep required fields required. Use custom decoding for documented format variations and return a clear decoding error for invalid required data. Do not silently substitute plausible values that could misrepresent important business data.

Real-world problem 7

The interface stutters while transforming data. How would you keep it responsive?

The scenario

A large sort or image transformation runs during a user interaction.

A strong answer

Profile to identify the expensive work, move CPU-heavy processing off the main actor, and return only the state needed for rendering to the main actor. Break up work when appropriate and measure frame responsiveness before and after the change.

Real-world problem 8

A new app version changes a persisted model and existing users lose data. How would you prevent it?

The scenario

A stored record schema changes, and decoding old records fails after an app update.

A strong answer

Version the stored format and provide explicit migrations from supported older versions. Make migrations transactional or recoverable, preserve the old data until the new format is verified, and test upgrades using fixtures from previous app releases.