All posts

Posts tagged with: Networking

15 posts found

A door standing half open in a dark room with red light spilling through the gap
Swift Foundation

URL(string:) Stopped Returning nil for Garbage in iOS 17. Your Validation Still Trusts It.

Since iOS 17, URL(string:) percent-encodes invalid characters instead of returning nil, so 'guard let url = URL(string: input)' accepts almost any text as a valid URL. Here's what changed, why it only kicked in when you updated Xcode, and how to validate URLs properly in Swift with scheme and host checks and URL(string:encodingInvalidCharacters:).

9 min read
Close-up of a red wax seal pressed onto a folded paper envelope
Swift Codable

Your Request Signature Fails on One Request in Ten. JSONEncoder Never Promised You the Same Bytes.

Signing a JSON body with HMAC in Swift breaks when you encode twice, when a Dictionary changes key order, or when JSONEncoder escapes slashes as \/. Here's why JSONEncoder output isn't canonical, how it breaks webhook and API signatures, and the fix: sign the exact Data you send.

9 min read
A red 'Road Ahead Closed' sign standing on a city sidewalk at night
Swift Networking

Your Base URL Has No Trailing Slash. URL(string:relativeTo:) Just Deleted Your /v2.

URL(string:relativeTo:) follows RFC 3986, so a base URL like https://api.example.com/v2 without a trailing slash quietly drops /v2 when you resolve an endpoint against it, and a leading slash on the endpoint drops the whole path. Here's why every request suddenly 404s, the xcconfig // comment trap that truncates your base URL, the URL equality and Codable surprises of relative URLs, and a safe join helper with a test.

8 min read
Close-up of paper calendar pages with printed dates
Swift iOS Development

JSONEncoder Sends Your Dates as Seconds Since 2001. Your Backend Thinks It's 1995.

Swift's JSONEncoder defaults to .deferredToDate, which encodes Date as a Double counting seconds from January 1, 2001, not 1970. Here's why round-trip tests never catch it, what it does to Node, Python and Go backends, and how to pin one date strategy for your whole app.

8 min read
A wall of brass post office boxes, one standing open and empty among the closed doors
Swift iOS Development

Codable Can't Tell You the Difference Between null and a Missing Key. Your PATCH Endpoint Can.

decodeIfPresent collapses an explicit JSON null and an absent key into the same nil, which makes 'clear this field' and 'leave it alone' indistinguishable. Here's the three-state wrapper that keeps them apart, and when you actually need it.

7 min read
A vintage ink bottle resting on an old postmarked envelope with a handwritten address
Swift iOS Development

URLComponents Leaves the + in Your Query Alone. Your Server Reads It as a Space.

URLComponents.queryItems percent-encodes spaces and ampersands but leaves + untouched, and most servers decode + as a space. Here's why mario+test@gmail.com arrives as 'mario test@gmail.com', and the one-line fix.

7 min read
A tray of metal letterpress type blocks, capital and lowercase letters sorted side by side
Swift iOS Development

Swift's uuidString Is Uppercase. Your Backend's UUIDs Aren't. Every String Comparison Between Them Fails.

UUID().uuidString returns uppercase hex while Postgres, JavaScript and Python emit lowercase, so string comparisons, dictionary keys, cache file names and Set deduplication silently miss. Here's where it bites in iOS apps and how to keep UUIDs typed until the boundary.

8 min read
A precision vernier caliper measuring a small component, jaws closed on a fine measurement
Swift iOS Development

Your Date Decoding Worked for a Year. Then the Backend Added Milliseconds.

JSONDecoder's .iso8601 date strategy rejects fractional seconds, so the day your API starts sending 2026-10-05T09:31:00.482Z every request fails to decode. Here's why the strict parser exists and the custom strategy that handles both shapes.

5 min read
Close-up of mismatched mechanical gears, the kind of quiet misalignment that convertToSnakeCase produces on acronym-heavy property names
Swift Codable

Codable's Snake Case Conversion Looks Like Free API Mapping. It Breaks on the First Acronym.

JSONEncoder's .convertToSnakeCase and JSONDecoder's .convertFromSnakeCase promise to erase the naming gap between Swift and your API. They do — right up until a property has an acronym in it, and then they fail silently on Optional fields instead of throwing.

5 min read
A delivery truck driving at night, headlights on, mid-route
URLSession Networking

Your Upload Doesn't Stop When Your App Gets Killed. It's Not Supposed To.

URLSession background sessions keep uploads and downloads running after iOS terminates your app — but only if you set them up before the crash, not after. Here's the delegate dance nobody reads the docs closely enough to get right.

5 min read
An old padlock and key resting against weathered metal — the kind of lock you can see is doing something, unlike a token sitting quietly in RAM
Swift Keychain

The Actor That Refreshes Your Token Perfectly. It Also Forgets It on Relaunch.

AuthTokenStore solved the token-refresh race condition with a Swift actor. What it never solved is where the token lives between launches. Here's why an in-memory actor isn't secure storage, and what a Keychain-backed version actually costs you.

8 min read
A brick wall with a visibly patched section of newer, different-colored bricks
Swift 6 Error Handling

Typed Throws in Swift 6: A Real Migration, and the Wall It Hits at a Protocol

Swift 6's typed throws (throws(SomeError)) let you catch errors exhaustively without a default case. Applied to BrewLog's real NetworkClient, here's what actually improves — and the protocol boundary where typed throws quietly stops helping.

7 min read
A black digital clock display against a dark background, evoking a countdown running out
Swift Swift Concurrency

Swift Just Got a Real Timeout API. Here's What We've All Been Duct-Taping Instead.

SE-0526 withDeadline was accepted into Swift on July 30, 2026 — a real, composable, absolute-time-limit API for async operations. I found the exact gap it fills in a real app's networking layer, fixed it today's way with a TaskGroup race, and lined it up against what withDeadline will let me delete once it ships.

10 min read
A relay runner mid-sprint on an outdoor track, baton in hand, captured at full stride — the same shape as a request that has to keep moving forward through a dropped connection, an expired token, or a second caller asking for the same thing.
Swift Networking

Retry, Token Refresh, and Request Deduplication in Swift

Day 23 of the 30-day iOS series. The three production concerns every 'build your own networking layer' tutorial skips, built as composable actors on top of Day 22's client — plus a real concurrency bug I found writing the test, not the code.

13 min read
A tangled mass of colorful telephone wires on the left resolving into a neatly organized black patch panel on the right — the same shape as replacing scattered URLSession calls with one clean networking layer.
Swift Networking

A Custom Networking Layer in 100 Lines of Swift — No Alamofire

Day 22 of the 30-day iOS series. URLSession, async/await, a generic Endpoint, and one typed error enum — the entire networking layer is 85 real lines, tested with a URLProtocol stub, and wired into a real BrewLog feature with a real local server.

11 min read