Building a Modern iOS Networking Library with Swift Concurrency
Article Summary
Emre Havan from Getir rebuilt their entire iOS networking stack from scratch. The result? A modern, async-first library that eliminated memory leaks and cut boilerplate codeābut not without hitting some painful Swift concurrency gotchas.
Getir's iOS team rewrote their networking library to embrace Swift's modern concurrency model, Codable support, and better testability. The article walks through their architectural decisions, from protocol design to URLSession management, revealing both wins and unexpected pitfalls along the way.
Key Takeaways
- Protocol-based request design eliminates repetitive baseURL declarations across endpoints
- Generic response wrapper preserves metadata without subclassing value types
- Convenience init pattern keeps internal protocols hidden while enabling dependency injection
- Pre-Swift 5.7 MainActor behavior caused non-deterministic UI crashes in production
- URLSession caching created memory leaks until proper invalidation in deinit
The team built a scalable, unit-tested networking library with async/await that's now powering Getir's iOS app, but learned hard lessons about Swift concurrency's non-obvious behaviors.
About This Article
Getir's team found that JSONSerialization was converting boolean query parameters to 1 and 0 instead of true and false. This caused their API requests to fail during URL encoding.
They added type checking to identify NSNumber values that were initialized as booleans. Before building URLQueryItems, they converted these values back to the correct boolean string format.
Query parameters now serialize correctly in all HTTP GET requests. This eliminated API contract violations that would have needed backend changes to fix.