iOS Networking
Priority: P0
Implementation Workflow
- Choose networking layer — Use native
URLSessionwith async/await for simple apps;Alamofirefor production APIs with interceptors. - Build URLs safely — Use
URLComponentsandURLQueryItem; never use string interpolation for URL parameters. - Decode with Codable — Use
Codablefor all JSON mapping. Prefersnake_casekey decoding strategies. - Add auth interceptor — Use
RequestInterceptorto injectAuthorization: Bearer <token>on all requests. - Handle token refresh — On 401, use
RequestInterceptor.onRetryto callrefreshToken()and retry. - Pin certificates — Use
ServerTrustManagerorTrustKitfor production-grade security.
See URLSession and Alamofire implementation examples
Anti-Patterns
- No Background UI Updates: Always dispatch to
@MainActoror main queue - No Manual
JSONSerialization: UseCodableandJSONDecoder - No Missing Timeouts: Set reasonable
timeoutInterval(30s default)