Getir Emre Havan Mar 6, 2023

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

Critical Insight

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.

They also built a clever mock networking system for UI tests that loads JSON data dynamically, but that's apparently a story for another article.

About This Article

Problem

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.

Solution

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.

Impact

Query parameters now serialize correctly in all HTTP GET requests. This eliminated API contract violations that would have needed backend changes to fix.