All posts

Posts tagged with: Foundation

13 posts found

Close-up of printed calendar pages with rows of dates
Swift Foundation

Calendar.current Isn't Always Gregorian. In Thailand, It's the Year 2569.

Calendar.current follows the user's chosen calendar, so on a phone set to the Buddhist or Japanese calendar, component(.year) returns 2569 or 8 instead of 2026. Here's how that breaks card expiry checks, age gates, filenames, and date math in Swift apps, and how to fix it with an explicit Gregorian calendar.

9 min read
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
A red vintage tram on a snowy Istanbul street with pedestrians walking past
Swift Foundation

You Shipped a Turkish Localization. Now "INFO" Lowercases to "ınfo" and Your String Matching Is Broken.

localizedLowercase and lowercased(with: .current) follow Turkish casing rules, where I lowercases to dotless ı and i uppercases to dotted İ. Here's how that breaks enum parsing, email normalization, file extensions and dictionary keys in Swift apps, why it only shows up after you add a Turkish localization, and the rule that fixes it.

8 min read
A stack of paper documents and folders piled on a desk
Swift Foundation

FileManager Says Your File Doesn't Exist. It's Right There. URL.path() Added %20 to the Name.

URL.path() returns a percent-encoded path by default, so FileManager.fileExists(atPath:) returns false for any file with a space or an accent in its name. Here's why path() and the old path property disagree, how it silently creates duplicate files, and how to fix file URL handling in Swift for good.

8 min read
Green binary code digits glowing on a dark computer screen
Swift Foundation

Your Binary Parser Passed Every Test. Then data[0] Crashed in Production Because the Slice Started at 4.

In Swift, a Data slice keeps the indices of the original buffer. After dropFirst, prefix(upTo:) or a range subscript, data[0] is out of bounds and crashes. Here's why Data is its own SubSequence, why tests built from fresh Data never catch it, and how to write byte parsers that work on any slice.

9 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 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 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 calculator resting on printed receipts and financial paperwork on a desk
Swift iOS Development

Your Receipt Says $0.13. Your Label Says $0.12. Swift Has Two Rounding Rules and You're Using Both.

Swift's Double.rounded() rounds half away from zero, but NumberFormatter, FormatStyle, and String(format:) round half to even. Here's why the same number displays two ways, the 1.005 trap, and how to pick one rounding rule and enforce it.

8 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 scattered pile of coins on a table, the kind of small change a rounding error is made of
Swift iOS Development

You Switched Your Prices to Decimal. Decimal(0.1) Still Went Through a Double First.

Swift's Decimal fixes binary floating-point money bugs, until you build one from a Double or a float literal. Here's why Decimal(0.1) can carry the exact error you were trying to escape, and the initializers that actually give you exact cents.

8 min read
Close-up of intricate pocket watch gears and mechanisms
Swift Performance

You're Creating a New DateFormatter on Every Cell Scroll. That's the Lag You Can't Explain.

DateFormatter and ISO8601DateFormatter are expensive to initialize — locale and calendar setup included — and creating one inside a loop or a SwiftUI view body is a quiet, common performance bug. Here's the actual cost and the fix.

5 min read