iOS Developer interview question
How do you design networking in iOS?
Design iOS networking around URLSession, typed request and response models, cancellation, timeouts, mapped errors, secure credential storage, retries for safe transient failures, and observable loading state.
Direct answer
What a strong answer covers
How it works
The networking layer wraps URLSession behind a small protocol so features depend on an interface and tests inject a fake. Requests are built from typed endpoints that encode path, method, query, and body; responses decode into Codable models with explicit date and key strategies. Errors become a single enum distinguishing transport failures, HTTP status ranges, and decoding problems, so the UI can decide between retry and a message. async/await with Task cancellation stops a request when its screen disappears, retries apply only to idempotent requests with backoff, and tokens live in the Keychain and refresh through a single in-flight task.
Example
A ProductsClient exposes func products(page: Int) async throws -> [Product] over an injected HTTPClient protocol; the SwiftUI view calls it inside .task so scrolling away cancels the load. When the access token expires the client awaits one shared refresh task, then retries the original request once, and a 401 after refresh signs the user out.
Common mistakes
- Using a shared singleton URLSession call directly in views and making them untestable.
- Retrying a failed POST that may have already created the resource.
- Storing the auth token in UserDefaults instead of the Keychain.
A useful answer structure
Answer from your own work.
Do not memorise a script: use only examples you can explain honestly in follow-up questions.
Open the desktop workspace and rehearse a clear answer in your own words.