All posts

Posts tagged with: Debugging

38 posts found

A pile of pastel paper labels, each with a different handwritten name
Swift Strings

Your Cache Key Says "user-Optional(42)". Swift String Interpolation Wrote It, and Xcode's Fix-It Made It Permanent.

Interpolating an optional into a Swift string produces "Optional(42)" or "nil", not the value. Here's how that ends up in URLs, cache keys, file names and analytics events, why Xcode's String(describing:) fix-it silences the warning without fixing the bug, and how to make optionals in strings impossible to ship.

9 min read
A plain cardboard box with no label sitting alone on a wooden floor
Swift Codable

Your Backend Added One Enum Case. Every User on the Old App Build Got an Empty Screen.

A Swift enum with a String raw value and synthesized Codable throws on any value it doesn't know, and that one throw takes down the whole object and the whole array around it. Here's how a harmless server-side addition empties your iOS app, the unknown-case and other(String) fixes, the encode-back trap, and the test that catches it before the App Store does.

9 min read
Rows of identical umbrellas in repeating colors hanging against a gray sky, each one indistinguishable from its twins
SwiftUI Swift

ForEach(items, id: \.self) Works Until Two Items Are Equal. Then SwiftUI Deletes the Wrong Row.

Using id: \.self in a SwiftUI ForEach or List makes the value itself the row's identity. Duplicate values, edited structs, and ForEach over indices all break that promise, causing wrong-row deletes, reset @State, lost TextField focus, and index-out-of-range crashes. Here's why, and the stable-ID fix.

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
A paper wall calendar with a grid of days, one square per date
Swift Foundation

You Saved the User's Birthday as a Date. Now It's a Day Early for Everyone in America.

A birthday, due date, or all-day deadline is a calendar day, not a moment in time. Storing it as a Swift Date pins it to midnight in one time zone, so it shifts by a day when the user travels or when your server parses "1990-03-05" as UTC. Here's why it happens, the LocalDate struct that fixes it, the noon hack that almost works, and the test that proves it.

9 min read
A small cafe storefront with its name painted on a sign above the door
Swift SwiftUI

Your Search Bar Can't Find "Café" When the User Types "cafe". String.contains Is Exact.

Filtering a SwiftUI list with String.contains or lowercased().contains misses accents, and users don't type accents. Here's why "cafe" never matches "Café", the difference between localizedCaseInsensitiveContains and localizedStandardContains, how to do it in SwiftData #Predicate, how to keep big lists fast, and the test that catches it.

9 min read
A close-up of an analog clock face with its hour and minute hands
Swift Foundation

Your Date Parsing Works on Every Test Device. Then One User Turns Off 24-Hour Time.

A fixed-format DateFormatter in Swift respects the user's 12/24-hour override, so a perfectly good server timestamp can come back nil for a handful of users. Here's why Apple's QA1480 bug still bites iOS apps, why en_US_POSIX is the fix, the time zone trap hiding next to it, and how to switch machine dates to ISO8601FormatStyle.

8 min read
A light switch mounted on a wall
Swift Foundation

UserDefaults.bool(forKey:) Returns false for a Key You Never Set. Your 'On by Default' Setting Ships Off.

UserDefaults.bool(forKey:) can't tell 'the user turned this off' from 'nobody has ever touched this', so every setting that's supposed to default to true quietly starts as false. Here's why, how register(defaults:) fixes it, why the @AppStorage inline default only fixes it for one view, and the widget and first-launch traps sitting right next to it.

9 min read
A close-up of a mechanical odometer with its digits mid-roll
Swift iOS Development

Swift Integers Don't Wrap. They Crash. And UInt Crashes the Moment You Subtract One From Zero.

Unlike C, Swift traps on integer overflow in release builds too. Here's the arithmetic-overflow crash in a progress bar, the UInt subtraction that can't go below zero, the UInt8(doubleValue) conversion that dies at 256.0, the Y2038 bug compiled into Int32(timeIntervalSince1970), the wrapping operators that hashes and PRNGs actually need, and the reporting and clamping APIs that replace the guesswork.

10 min read
A large clock tower face seen from below against a pale sky, hands frozen mid-afternoon
Swift iOS Development

Adding 86,400 Seconds Isn't Adding a Day. Twice a Year Your Streak Counter Finds Out.

A day isn't always 86,400 seconds long. Daylight saving transitions make it 23 or 25 hours, which quietly breaks streak counters, 'last 7 days' queries, and repeating reminders. Here's why Calendar exists and how to do date math that survives March.

7 min read
A heap of ornate antique brass keys piled on top of each other, many of them nearly identical
Swift iOS Development

Dictionary(uniqueKeysWithValues:) Is a Promise. One Duplicate ID From Your Backend and Your App Crashes.

Swift's Dictionary(uniqueKeysWithValues:) traps on a duplicate key, in release builds too. Here's how one repeated ID from an API crashes your iOS app, the uniquingKeysWith and grouping fixes, Unicode keys that collide, and SwiftUI ForEach's duplicate-ID cousin.

9 min read
Discarded paper thrown away in a waste bin, like an error swallowed by try?
Swift iOS Development

guard let try? Is a Neuralyzer for Your Errors. Swift's New guard do/catch Pitch Wants to Fix It.

guard let x = try? throws away the error, so a renamed JSON key becomes a silent empty screen. Here's what try? really hides in iOS apps (decoding failures, nil vs thrown, Task.sleep cancellation loops), the do/catch pattern that keeps the error without nesting today, and what the guard do ... catch Swift Evolution pitch proposes.

9 min read
Close-up of a calculator with its display showing an error instead of a number
Swift iOS Development

One NaN Got Into Your Array. Now sorted(), contains(), and Set Are All Quietly Lying.

Double.nan isn't equal to itself, so one NaN silently breaks Swift's sorted(), contains(), firstIndex(of:), max(), Set and Dictionary, and even your clamp function. Where NaN comes from in iOS apps, why it spreads, and how to stop it at the boundary.

9 min read
A paper calendar page with dates and a pen resting on it, ready for a new year of plans
Swift iOS Development

Your DateFormatter Says It's Next Year. Capital YYYY Isn't the Year You Think It Is.

In a DateFormatter pattern, YYYY is the week-based year, not the calendar year. For a few days around New Year it prints the wrong year, breaking receipts, filenames, cache keys, and API payloads. Here's why, which dates it hits per locale, and how to catch it before December does.

9 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
Close-up of a round clock face with numbers arranged in a circle, the kind of wraparound that modular arithmetic is supposed to model
Swift iOS Development

Swift's % Isn't Modulo. -1 % 7 Is -1, and Your Carousel Just Crashed.

Swift's % operator is a remainder, not a modulo: its result takes the sign of the left-hand side, so -1 % 7 is -1, not 6. Here's why wraparound indexes crash on the back button, why Double has no % at all, and the one-line helper that fixes it.

8 min read
A deck of playing cards scattered across a table in no particular order
Swift iOS Development

Your Set Iterates in a Different Order Every Launch. That's Not a Bug, It's a Security Feature.

Swift randomizes its hash seed on every process launch, so Set and Dictionary iteration order changes between runs. Here's why that exists, the three places it silently breaks your app, and how to get stable order without giving up the hash table.

7 min read
A row of empty theater seats, each with a small brass number plate
Swift Collections

enumerated() Gives You an Offset, Not an Index. On a Slice Those Are Different Numbers.

for (i, item) in collection.enumerated() reads like it hands you an index, and on a plain Array it happens to. Feed it an ArraySlice and the same loop crashes with Index out of range. Here's the distinction Swift is actually drawing, and the two fixes.

5 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
A closed shop at night with the interior lights still burning
Swift Concurrency

@MainActor on Your Class Does Not Cover deinit. That's Where Your Last Data Race Lives.

You marked the whole class @MainActor, the compiler went quiet, and you assumed every member was protected. deinit isn't. It runs wherever the final release happens, which can be any thread — and Swift will happily let you touch main-actor state from it.

6 min read
A stack of envelopes with handwritten addresses, one marked as returned to sender
Swift iOS Development

Your Saved File Paths Break When the User Gets a New iPhone. The Files Never Moved.

Storing an absolute file URL in your database works perfectly until a device restore or iCloud sync hands your app a new container path. Here's why the bug survives every test you run, and how to store paths that keep working.

7 min read
A deck of playing cards spread and shuffled across a surface
Swift iOS Development

Swift's sorted() Makes No Promise About Equal Elements. Your List Reshuffles for Free.

Swift's sort is not documented as stable, so two elements that compare equal can swap places between runs. Here's why that silently breaks SwiftUI list animations and paginated APIs, and how to make your sort total instead of hoping for the best.

6 min read
The brass pendulum and gears of an old clock mechanism, stopped mid-swing
iOS Development Swift

Your Timer Stops Every Time the User Scrolls. Timer Is Working Exactly as Documented.

A scheduled Timer silently stops firing the moment a user touches a scroll view, because scheduledTimer adds itself to the run loop's default mode and scrolling switches to tracking mode. Here's the mechanism, and why reaching for .common isn't automatically the right fix.

6 min read
A marionette puppet suspended on strings, controlled from above by someone out of frame
iOS Development Swift

Your Crash Rate Doubled Overnight. You Didn't Ship Anything.

A third-party SDK can crash your already-shipped iOS app without you releasing a single line of code. Here's the mechanism behind server-driven SDK crashes, why pinning your dependency versions doesn't protect you, and the kill switch you need to ship before you need it.

9 min read
A microphone close to a speaker, the setup that causes audio feedback loops
SwiftUI Swift

SwiftUI's Purple Warning Isn't Cosmetic. 'Publishing Changes From Within View Updates' Means You Raced Your Own Render.

Xcode's console warns 'Publishing changes from within view updates is not allowed, this will cause undefined behavior' and most developers just scroll past it. Here's what SwiftUI is actually telling you, the three common ways you trigger it, and why ignoring it eventually costs you a view that won't stop re-rendering.

7 min read
Close-up of cracked, dry ground splitting apart
Swift iOS Development

You Can Mutate an Object Sitting Inside a Set. Swift Won't Stop You. It Should Terrify You.

Swift's Set and Dictionary assume a value's hash never changes after you insert it. Mutate a class instance that's already stored in one, and the collection silently corrupts — contains() returns false for an object you can see right there when you iterate. Here's why, and how to actually avoid it.

7 min read
A doorway seen from inside a dim hallway, suggesting the same threshold crossed again and again
SwiftUI iOS Development

SwiftUI's .onAppear Doesn't Mean 'First Appearance.' It Means 'Any Appearance.'

onAppear fires every time a SwiftUI view becomes visible again, not just once — including every time you pop back to it in a NavigationStack. Here's why that duplicates network calls and how to fix it with .task(id:) or a one-shot flag.

5 min read
A single closed door at the end of a long hallway
Swift Concurrency Async Await

A Continuation Can Only Be Resumed Once. Swift Won't Stop You From Trying Twice.

withCheckedContinuation bridges callback-based APIs into async/await, but resuming it twice crashes at runtime and resuming it zero times hangs forever — and the compiler catches neither. Here's the failure shape and the fix.

6 min read
A red warning light glowing in a dark room
Swift Concurrency

Thread Sanitizer Just Flagged Your Correct Code as a Race. Swift Might Finally Let You Say 'I Know.'

SE-0550 proposes a @noSanitize attribute for Swift functions, letting you opt individual functions out of ASan/TSan instrumentation. Here's the real problem it solves, and the sharp edges it comes with.

6 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 single rope cut cleanly with scissors, the two ends falling apart
Swift Swift Concurrency

Task.detached Isn't Task With Extra Steps. It Throws Away Everything Task Inherited For You.

Task.detached in Swift concurrency looks like a stronger version of Task, but it silently drops actor isolation, priority, and task-local values. Here's what actually breaks, and when detached is genuinely the right call.

5 min read
A close-up of an hourglass with sand mid-fall
Swift Concurrency

Your defer Didn't Fire Late. It Fired Exactly on Time — Just Not the Time You Meant

Swift's defer runs at the end of the enclosing scope, not the end of the function. Inside an if/else branch, that difference can silently defeat the cleanup you thought you wrote.

7 min read
A runner abruptly stopping mid-stride on a track
SwiftUI Swift Concurrency

SwiftUI Cancels Your .task When the View Disappears. Your await Doesn't Get the Memo.

SwiftUI's .task modifier automatically cancels its Task when a view disappears — but cancellation is cooperative, not magic. Here's why your network call keeps running anyway, and the three checks that actually stop it.

5 min read
Scattered puzzle pieces on a table, none of them quite matching — a stand-in for a view SwiftUI keeps mistaking for a different one
SwiftUI Swift

SwiftUI Reset My State for No Reason. The Bug Was Identity, Not Bindings.

A text field kept clearing itself on every re-render, and no amount of staring at @State fixed it. The actual cause was SwiftUI's view identity system silently deciding my view was a brand new one. Here's how identity actually works and the three ways to break it.

8 min read
A dimly lit warehouse aisle at night, empty and waiting
Background Tasks BGTaskScheduler

Your Background Task Isn't Broken. iOS Just Decided It Wasn't Worth Running.

BGTaskScheduler doesn't promise your task will run — it's a request, scored against battery, usage patterns, and network state. Here's how the budget actually works, how to test it without waiting three days, and how to design a sync that survives never being called.

7 min read
A studio microphone against a dark background, standing in for on-device speech transcription.
Swift Speech Framework

Apple's On-Device Speech API Reserves Five Locale Slots. You Never Get Them Back.

A developer who actually shipped an app on SpeechTranscriber and Foundation Models found that AssetInventory.release(reservedLocale:) doesn't release anything. I checked Apple's own docs against the bug report, and the gap between what's documented and what happens on a real device is the whole story.

8 min read
A tangled knot of cables, impossible to trace one strand from end to end
Swift SwiftUI

Weak Self Isn't the Retain Cycle Fix You Think It Is in @Observable

The old [weak self] advice was written for closures capturing classes. @Observable changes what actually gets captured, and in a few common SwiftUI patterns weak self silently does nothing at all. Here's where it still matters and where it's dead weight.

7 min read
An open drawer of a vintage card catalog cabinet, packed with densely filed index cards
SQLite SwiftData

A 16-Year-Old SQLite Bug Just Surfaced. Your SwiftData App Is Sitting on the Same Engine.

Tailscale spent six months and 19 database corruptions tracking down the SQLite WAL-Reset bug, unfixed since 2010 and patched in 3.51.3. SwiftData and Core Data both run on SQLite in WAL mode — so I checked which version iOS 26.2 actually ships, and what it means for your app.

9 min read