Data & Networking
Two responsibilities sit at the bottom of almost every app: talking to a server, and keeping data on the device. They look separate, but an interview tests them together because they share one discipline — knowing what runs on which thread and what may be stored where. Networking is inherently asynchronous and must never block the main thread; URLSession gives you data, upload, and download tasks, Codable turns JSON into your types, and URLCache revalidates responses for free. Get the model wrong and the UI freezes on a slow network.
Persistence is a choice problem. iOS hands you a ladder of stores — UserDefaults for small preferences, the Keychain for secrets, the file system for blobs, and Core Data or SwiftData for a queryable object graph — and the interview trap is putting data in the wrong rung: a secret in UserDefaults, a re-downloadable video in Documents/, or an NSManagedObject passed across contexts. We cover both layers and the rules that keep them honest.
Topic map
- Networking —
URLSessiontasks and configurations,async/awaitversus the delegate API, decoding JSON withCodable, HTTP caching viaURLCache, background transfers, retry with backoff, authentication challenges, ATS and certificate pinning, and offline handling. - Persistence — the storage ladder and what belongs on each rung:
UserDefaults, the Keychain, the file system, Core Data with its context-threading rule, and SwiftData; plus migration and the secrets trap.
Common traps
| Mistake | Consequence |
|---|---|
| Running a request on the main thread | The UI freezes for the duration of the network call |
Storing a token or password in UserDefaults | A plaintext secret in a plist, readable off a backup |
Putting re-downloadable files in Documents/ | iCloud backup bloat and possible App Review rejection |
Passing an NSManagedObject across contexts/threads | Corruption or a crash — pass the objectID and re-fetch |
| Pinning a certificate with no rotation plan | The app cannot connect once the pinned cert is rotated |
| Retrying every failure with a fixed delay | A thundering herd re-overloads the recovering server |
Interview relevance
Data and networking questions test whether you know where work runs and where bytes live. A candidate who says "the request runs off the main thread and I decode with Codable, and secrets go in the Keychain, never UserDefaults" is instantly ahead of one who reaches for UserDefaults for everything and blocks the main thread on a synchronous fetch.
Typical checks:
- Which
URLSessiontask and configuration fits data, uploads, downloads, and background transfers. - How HTTP caching and
Codabledecoding work, and why the request stays off the main thread. - Which store each kind of data belongs in, and what must never go in
UserDefaults. - The Core Data context-threading rule and how you move an object between contexts.
Common wrong answer: "just save everything to UserDefaults and fetch synchronously so the data is ready." In reality synchronous fetches freeze the UI, UserDefaults is an unencrypted plist that is wrong for secrets and large data, and the right answer is asynchronous networking plus the correct store for each kind of data.