20 frequently asked iOS interview questions. iOS development is an in-demand field focused on building Swift, SwiftUI, and UIKit apps, solving lifecycle, concurrency, networking, storage, performance, testing, and App Store release tasks. The questions cover different levels, and you can practice answering them aloud in our interview trainer.
1What is `@Binding` in SwiftUI, and how is it different from `@State`?
If the parent owns a Boolean setting in @State, passing setting gives the child a value to display or use. The parent can supply a new value when it updates, but assigning to a separate local copy in the child does not write back to the parent's state. Passing $setting to a child with @Binding instead supplies read/write access to that existing storage. A Toggle in the child can then change the same setting without creating a competing source of truth. The binding itself does not own or persist the data; the parent's state lifetime still matters. If edits should apply only after Save, I would intentionally create a draft in the editor and send an explicit save action or assign through the binding on confirmation. That is a different interaction contract from immediate two-way editing, and it needs an explicit cancellation policy.
struct ParentView: View {
@State private var isOn: Bool = false
var body: some View {
VStack {
Text("Switch is: \(isOn ? "ON" : "OFF")")
// Pass binding using $ prefix
CustomToggle(isOn: $isOn)
}
}
}
struct CustomToggle: View {
@Binding var isOn: Bool
var body: some View {
Button("Toggle") {
isOn.toggle() // Modifies parent's @State
}
}
}
2What is the role of a provisioning profile in an iOS app release?
In an iOS release, a provisioning profile acts as a cryptographically signed package that bridges Apple's security requirements with the app binary and target devices. Its primary role is to tell the iOS operating system and App Store Connect that the application is authorized to run under specific distribution rules. A provisioning profile bundles together several critical pieces: the App ID (Bundle Identifier), the authorized signing certificate(s) confirming who built the app, the entitlements and capabilities granted to the app (such as Push Notifications, Sign in with Apple, or iCloud), and—in non-App Store profiles like Development or Ad-Hoc—a list of allowed device UDIDs. For App Store release profiles, individual device UDIDs are omitted because Apple allows distribution to any consumer device via the App Store.
Provisioning Profile (.mobileprovision)
├── App ID / Bundle Identifier (e.g., com.example.app)
├── Certificates (Public key / Distribution Certificate)
├── Entitlements (e.g., Push Notifications, Associated Domains)
└── Device UDIDs (Present for Development/Ad-Hoc; omitted for App Store distribution)
3What does it mean for an iOS app to run work in the background, and what basic limits does the system place on that work?
Running work in the background on iOS means executing code when the app is not currently active on screen or visible to the user. When a user exits an app, it transitions from the active foreground state to the background, and shortly thereafter into a suspended state where its execution is paused, though its memory remains in RAM. To preserve battery life, system responsiveness, and device resources, iOS strictly controls background execution. The system limits how long an app can execute code once backgrounded (only a brief, system-controlled period by default; a finite background-task assertion or an appropriate background API may grant additional execution, with no fixed duration guaranteed), throttles CPU and network priority, and can terminate suspended apps if the device encounters memory pressure.
4What is a Combine publisher, and how does it differ from a subscriber in a typical iOS data flow?
In Combine, a Publisher emits a stream of values over time and can finish with a completion event (either completing successfully or failing with an error). It declares two associated types: `Output` (the type of data it produces) and `Failure` (the type of error it can emit). A Subscriber receives values and lifecycle events from a publisher. In a typical iOS data flow, publishers act as the source or producer of asynchronous events (such as network responses, notifications, or user inputs), while subscribers act as the consumers that react to emitted values, handle errors, and respond to completion (such as updating UI state or writing to a database). The subscriber attaches to a publisher, receives a subscription token, and requests demand for elements.
import Combine
// Publisher: emits a sequence of integers
let numberPublisher = [1, 2, 3].publisher
// Subscriber: consumes the emitted integers
let cancellable = numberPublisher.sink(
receiveCompletion: { completion in
switch completion {
case .finished:
print("Finished")
case .failure(let error):
print("Error: \(error)")
}
},
receiveValue: { value in
print("Received: \(value)")
}
)
5What does async/await mean in Swift, and how would you use it to call an asynchronous API from an iOS app?
`async/await` is Swift's built-in syntax for writing asynchronous code in a linear, readable, sequential manner rather than using nested closures and completion handlers. Marking a function with `async` tells the compiler that the function can suspend its execution while waiting for long-running work (such as network requests or file I/O) to finish. The `await` keyword indicates a suspension point: execution of the current function pauses, freeing up the underlying thread to do other work, and resumes once the awaited result or error is ready. To call an asynchronous API in an iOS app, you call the `async` method preceded by `await` (and `try await` if the function throws) from within an asynchronous context, such as inside another `async` function or a `Task` block.
6When would you use UserDefaults in an iOS app, and what kinds of data should not be stored there?
UserDefaults is designed for storing small, lightweight user preferences, settings, and flags across app launches (for example, theme preferences, volume level, or a `hasSeenOnboarding` boolean flag). It supports property list types such as String, Int, Double, Bool, Date, Data, Array, and Dictionary. You should NOT store: 1. Sensitive information (such as user passwords, private keys, or authentication tokens) because UserDefaults stores data unencrypted in a plaintext plist file. 2. Large datasets, documents, or media files (like images, audio, or large JSON payloads) because the entire plist is loaded into memory when accessed, which leads to high memory overhead and slows down app launch.
// Saving simple preference values
UserDefaults.standard.set(true, forKey: "hasCompletedOnboarding")
UserDefaults.standard.set("dark", forKey: "preferredTheme")
// Reading values back
let hasCompletedOnboarding = UserDefaults.standard.bool(forKey: "hasCompletedOnboarding")
let theme = UserDefaults.standard.string(forKey: "preferredTheme") ?? "system"
7What is ARC in Swift, and how does it manage the lifetime of class instances in an iOS app?
ARC (Automatic Reference Counting) is Swift's compile-time memory management mechanism for tracking and managing the lifetime of class instances (reference types). Every time a new instance of a class is created and assigned to a strong reference, ARC tracks an internal reference count for that instance. As long as at least one strong reference to an instance exists, ARC keeps the instance in memory. When all strong references are removed and the reference count drops to zero, ARC immediately deallocates the instance to free memory, automatically invoking the instance's `deinit` method right before deallocation. Unlike runtime garbage collection in environments like Java or .NET, ARC does not run periodic sweep cycles; the Swift compiler inserts appropriate retain and release calls into the binary at compile time.
class User {
let name: String
init(name: String) {
self.name = name
print("\(name) initialized")
}
deinit {
print("\(name) deallocated")
}
}
var ref1: User? = User(name: "Alice") // count = 1
var ref2: User? = ref1 // count = 2
ref1 = nil // count = 1
ref2 = nil // count = 0 -> deinit called
8How do you perform a simple HTTP GET request with URLSession in an iOS app?
To perform a simple HTTP GET request in an iOS app, you create a URL object and pass it to a URLSession instance, such as URLSession.shared. You can execute the request using a data task completion handler (URLSession.shared.dataTask(with: url) { data, response, error in ... }) or using modern Swift concurrency (let (data, response) = try await URLSession.shared.data(from: url)). When using the traditional data task approach, you must call .resume() on the task to start it, handle any transport error, inspect the HTTPURLResponse status code, and ensure any UI updates are dispatched to the main thread.
guard let url = URL(string: "https://api.example.com/items") else { return }
let task = URLSession.shared.dataTask(with: url) { data, response, error in
if let error = error {
print("Network error: \(error.localizedDescription)")
return
}
guard let httpResponse = response as? HTTPURLResponse, (200...299).contains(httpResponse.statusCode) else {
print("Server error or invalid status code")
return
}
if let data = data {
DispatchQueue.main.async {
// Update UI on main thread
}
}
}
task.resume()
9What is Instruments in Xcode, and how would you use it to investigate a simple performance problem in an iOS app?
Instruments is Apple's performance profiling and analysis tool bundled with Xcode. It allows developers to monitor runtime behavior, CPU usage, memory allocations, memory leaks, and UI rendering performance. To investigate a simple performance issue (such as UI stutter or high CPU usage), you launch Instruments from Xcode (via Product -> Profile), choose an appropriate template (such as Time Profiler for CPU bottlenecks or Allocations/Leaks for memory problems), and record a trace while reproducing the problematic user flow on a device. After recording, you analyze the call tree and heaviest stack traces to pinpoint the exact methods causing delays or excessive resource consumption, allowing you to measure and locate the bottleneck before making code changes.
1. In Xcode, select Product -> Profile (Builds with Release optimizations).
2. Select the 'Time Profiler' template.
3. Click Record and perform the sluggish action in the app.
4. Stop recording.
5. Inspect the Call Tree tab:
- Enable 'Separate by Thread' and 'Hide System Libraries'.
- Trace the heaviest call stack on the Main Thread to identify the blocking function.
10What is APNs and what role does it play in delivering push notifications to an iOS app?
APNs (Apple Push Notification service) is Apple's cloud-based intermediary service that securely routes push notifications from your backend servers (provider servers) to Apple devices. Because mobile devices cannot maintain continuous, open socket connections to every individual app backend without draining battery and consuming excessive network bandwidth, Apple maintains a single persistent, low-power connection between each device and APNs. When your app registers for remote notifications, APNs generates a unique, opaque device token identifying that specific app installation on that specific device. The app sends this token to your backend provider server. When the provider wants to notify the user, it constructs a payload and sends it alongside the device token to APNs over HTTP/2. APNs then locates the active connection for that device and delivers the push notification payload directly to iOS, which displays the alert or wakes the app as configured.
11How would you merge newly fetched stories into an existing UITableView feed so fetched stories appear first and duplicate IDs appear once?
Build the new list in fetched order, then append existing entries whose IDs were unseen. Apply the update on the main actor and finish the refresh control in both success and failure paths.
12What distinction matters between a Swift actor and an ordinary reference type when several tasks access mutable data?
An ordinary class can be shared by several tasks, but its mutable properties are not automatically protected from concurrent access. A Swift actor provides an isolation domain: access to its isolated state is coordinated by the actor executor, and crossing that boundary generally requires an asynchronous operation. This helps prevent data races without manually locking each property. It does not give the actor a dedicated thread or make an entire async method one indivisible transaction. At an await suspension point, other actor work can run and change state, so assumptions made before the await may need rechecking afterward. I would keep invariant-changing synchronous sections together and use explicit versions or state transitions when an operation spans suspension. Nonisolated members and values crossing boundaries must follow their own safety requirements. Actors protect state access, while application-level ordering and correctness still need design.
13How would you test an iOS view model's loading, success and cancellation transitions without calling the real API?
I would depend on a small API protocol and inject a fake whose async result is controlled by the test. The test starts loading, verifies the loading state, then completes the fake with data or an error and checks the resulting state and preserved data. Cancellation tests should verify that the task is cancelled, loading is cleared according to the UI contract, and cancellation is not shown as an ordinary failure unless intended. A fake can deliberately complete late to verify that an obsolete request cannot overwrite a newer selection. Tests should run with the view model's actor isolation and use explicit synchronization or a controllable clock/scheduler rather than arbitrary sleeps. I would also cover repeated load actions and deallocation or screen exit where relevant. No real network or credentials are needed, and assertions should target observable behavior rather than internal implementation steps.
14How would you build a Combine pipeline for a search text field that debounces input, ignores duplicates, performs a network request, and updates the UI safely?
To build a safe search pipeline in Combine: 1. **Debounce & Deduplicate:** Take the search query publisher (e.g. `$queryText`), apply `.debounce(for: .milliseconds(300), scheduler: RunLoop.main)` to wait for typing pauses, and `.removeDuplicates()` to ignore unchanged query strings. 2. **Network Request & Cancellation:** Map each query to a network request publisher and flatten using `.switchToLatest()`. This automatically cancels in-flight requests when a new search query arrives, avoiding race conditions and stale results. 3. **Isolate Errors:** Catch network errors inside the inner publisher (e.g. `.catch { _ in Just([]) }`) so network failures do not terminate the outer search text stream. 4. **Main Thread Delivery:** Apply `.receive(on: DispatchQueue.main)` before updating state or assigning to UI properties.
15How would you use Swift async/await and Task cancellation to implement a screen that loads data from the network and avoids updating the UI after the user navigates away?
I would make the network load an `async` function on a service or view model and run it from a `Task` whose lifetime is tied to the screen. In UIKit, that usually means storing something like `var loadTask: Task<Void, Never>?` on the view controller or view model, starting it when the screen should load, and cancelling it in `viewWillDisappear`, `deinit`, or before starting a newer request depending on the desired lifetime. In SwiftUI, I would prefer `.task` or `.task(id:)` when possible because SwiftUI cancels it when the view disappears or the id changes. Inside the task, I would call the async network API with `try await`, handle cancellation separately from real errors, and check cancellation before applying results if there are multiple awaits or processing steps. UI state changes must happen on the main actor, either by making the view model `@MainActor` or by using `await MainActor.run`. To avoid stale UI, I would cancel previous tasks, avoid detached/global tasks for screen-bound work, and optionally compare a request id or current item id before applying the result.
@MainActor
final class UsersViewController: UIViewController {
private var loadTask: Task<Void, Never>?
private let service: UserService
override func viewDidLoad() {
super.viewDidLoad()
loadUsers()
}
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
loadTask?.cancel()
}
private func loadUsers() {
loadTask?.cancel()
loadingView.isHidden = false
loadTask = Task { [weak self] in
do {
let users = try await self?.service.fetchUsers() ?? []
try Task.checkCancellation()
guard let self else { return }
self.loadingView.isHidden = true
self.tableModel = users
self.tableView.reloadData()
} catch is CancellationError {
// User navigated away or a new load replaced this one; do not update UI.
} catch {
guard let self else { return }
self.loadingView.isHidden = true
self.showError(error)
}
}
}
}
16How would you choose between UserDefaults, Keychain, files, SQLite, and Core Data for different types of app data?
Choosing the appropriate iOS storage mechanism depends on data sensitivity, size, relational complexity, query requirements, and backup lifecycle: 1. **Keychain**: For sensitive data (auth tokens, passwords, encryption keys). It supports encrypted storage and access controls; biometric templates remain managed by the system and are not exposed to apps. Keychain does not guarantee secrecy against code executing with the app's authorized access, and persistence across reinstall must not be treated as a storage contract. 2. **UserDefaults**: For lightweight, non-sensitive preferences and flags (e.g., `hasCompletedOnboarding`, theme preference). Because it is optimized for small preferences, it should not be used for large datasets, media, or sensitive tokens. 3. **File System (Documents / Caches / Application Support)**: For discrete files and large binary blobs (downloaded images, audio, PDFs). `Documents` is user-facing and backed up to iCloud; `Caches` is for purgeable re-downloadable content; `Application Support` is for non-user-facing persistent files. 4. **SQLite**: For structured, tabular data needing fast indexed queries, bulk operations, or cross-platform database sharing without object-graph overhead. 5. **Core Data / SwiftData**: For complex object graphs with relationships, change tracking, faulting, undo management, and direct integration with UIKit (`NSFetchedResultsController`) or SwiftUI (`@Query`).
17In a production UIKit screen with callbacks from a view model, how would you decide whether to capture self as weak, unowned, or strong in closure handlers?
In UIKit architecture where a view controller interacts with a view model via callbacks, the capture strategy is determined by ownership and lifecycle: 1. `[weak self]`: The standard and safest approach for stored or escaping closures (such as view model event callbacks or asynchronous network/data completion handlers). Because the view controller owns the view model, capturing `self` strongly in a callback stored by the view model creates a strong reference cycle (`VC -> VM -> closure -> VC`). `[weak self]` converts `self` into an optional (`UIViewController?`), allowing `self` to deallocate cleanly and preventing memory leaks. 2. `[unowned self]`: Assumes `self` will never be nil when the closure executes. It should be used with extreme caution in UI screens. If an asynchronous task or callback completes after the view controller has been dismissed and deallocated, accessing `unowned self` causes a fatal runtime crash. For this reason, `[weak self]` is generally preferred over `unowned` in production UIKit UI callbacks. 3. Strong capture (default, no capture list): Appropriate when the closure is non-escaping (e.g., standard collection operations like `map`/`filter`) or when the closure is short-lived and does not create an ownership cycle back to `self`.
final class ProfileViewController: UIViewController {
private let viewModel: ProfileViewModel
init(viewModel: ProfileViewModel) {
self.viewModel = viewModel
super.init(nibName: nil, bundle: nil)
}
required init?(coder: NSCoder) { fatalError() }
override func viewDidLoad() {
super.viewDidLoad()
// VM stores the callback -> capture weak self to break retain cycle
viewModel.onDataUpdated = { [weak self] state in
guard let self else { return }
self.updateUI(with: state)
}
}
private func updateUI(with state: ProfileState) { /* Update views */ }
}
18How could a team introduce SwiftUI into a large UIKit application one screen at a time?
I would choose a bounded screen with clear inputs and outputs, then embed its SwiftUI view in a UIHostingController while keeping the existing UIKit navigation and application lifecycle. Shared business logic and repositories can remain framework-independent, with one explicit owner for each piece of screen state. When SwiftUI needs an existing UIKit control or controller, UIViewRepresentable or UIViewControllerRepresentable can bridge it, using a coordinator for callbacks where appropriate. The integration needs deliberate handling of navigation, dismissal, focus, accessibility, theming and deployment-version availability. I would add tests around the screen's behavior and transitions, compare performance and appearance, and roll it out behind a reversible entry point if risk warrants it. Repeating this screen by screen lets the team learn without maintaining two competing sources of truth or forcing a simultaneous rewrite of working UIKit features.
19You are releasing a high-traffic iOS app with a database migration and a backend API change; how would you design the rollout plan to minimize user impact?
Designing a rollout plan for a high-traffic iOS app involving database migrations and backend API changes requires decoupling deployment from feature activation due to iOS client constraints (asynchronous user updates and inability to force client-side binary rollbacks). 1. Backend Compatibility: Implement an expand-and-contract strategy. Deploy API v2 alongside API v1 so that both legacy and updated client versions function concurrently without breaking changes. 2. Resilient Database Migration: Ensure local schema migrations (e.g., SQLite, Core Data, SwiftData) are idempotent, non-destructive, and safely handle multi-version jumps (e.g., upgrading from N-3 to N) without blocking the main thread or causing launch crash loops. 3. Dynamic Gating: Ship the new client features dark behind server-driven feature flags/remote configuration. Keep the feature flag disabled during initial distribution. 4. Phased Rollout & Monitoring: Distribute the app via App Store Phased Release (a 7-day staged rollout). Continuously monitor telemetry, crash rates, database migration success metrics, and API error rates. If anomalies occur, pause the phased rollout in App Store Connect and toggle feature flags off without requiring an emergency binary rollback.
Phase 1 (Backend Expand): Deploy API v2 supporting both new and legacy payloads.
Phase 2 (Client Distribution & Migration): Release client v2.0 via App Store Phased Release (1% -> 100%). DB migrates safely on first launch. Feature flag remains OFF.
Phase 3 (Validation & Feature Enablement): Monitor crash rates & migration success. Incrementally ramp Remote Config flag (10% -> 50% -> 100%).
Phase 4 (Backend Contract): Once legacy app adoption drops below deprecation threshold, sunset API v1.
20You are designing offline-first sync for a notes app where edits must eventually sync across devices, but iOS may defer or cancel background work. What background execution architecture would you choose?
An offline-first sync architecture treats the local database (such as SQLite, Core Data, or SwiftData) as the immediate single source of truth for UI state, while mutations are appended to a persistent outbox queue on disk so that unsent edits survive process death. To manage iOS's opportunistic and non-deterministic background execution, background work is structured across multiple tiers: 1. Outbox Flush on Backgrounding: Initiated via `UIApplication.shared.beginBackgroundTask(expirationHandler:)` to finish in-flight or quick pending mutations. 2. Opportunistically Scheduled Sync: Registered with `BGTaskScheduler` using `BGAppRefreshTask` for lightweight metadata/delta sync and `BGProcessingTask` for heavier sync operations. 3. Large Asset Sync: Handled out-of-process via a background `URLSessionConfiguration` using file uploads/downloads. 4. Server-Triggered Sync: Opportunistic wakeups via silent push notifications (`content-available: 1`). Because background tasks can be interrupted or rescheduled at any point, operations must use client-generated idempotency keys (e.g., UUIDs) to allow safe retries without duplicating data. If a task's `expirationHandler` is called, in-flight work must be cancelled immediately, uncommitted operations marked back to pending, and `setTaskCompleted(success: false)` called. Also sync when the app is foregrounded and after local edits, with one coordinated sync owner. Background launch is never guaranteed, so do not promise a fixed convergence deadline. Eventual consistency is pursued using conflict resolution mechanisms such as CRDTs, version vectors combined with a merge policy, or last-write-wins with deletion tombstones, ensuring remote deltas do not overwrite uncommitted local outbox mutations.
import BackgroundTasks
import Foundation
final class NoteSyncCoordinator {
static let shared = NoteSyncCoordinator()
private let syncTaskID = "com.notesapp.sync.refresh"
func registerSyncTask() {
BGTaskScheduler.shared.register(forTaskWithIdentifier: syncTaskID, using: nil) { task in
guard let refreshTask = task as? BGAppRefreshTask else { return }
self.handleAppRefresh(task: refreshTask)
}
}
func scheduleNextSync() {
let request = BGAppRefreshTaskRequest(identifier: syncTaskID)
request.earliestBeginDate = Date(timeIntervalSinceNow: 15 * 60)
try? BGTaskScheduler.shared.submit(request)
}
private func handleAppRefresh(task: BGAppRefreshTask) {
scheduleNextSync()
let syncTask = Task {
do {
try await SyncEngine.shared.flushPersistentOutboxAndFetchDeltas()
task.setTaskCompleted(success: true)
} catch {
task.setTaskCompleted(success: false)
}
}
task.expirationHandler = {
syncTask.cancel()
}
}
}