All posts

Posts tagged with: Strings

8 posts found

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 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 printed document with several lines blacked out by a heavy marker
Swift Strings

String(decoding:as:) Never Fails. It Just Quietly Swaps Your Bytes for �.

Swift has two ways to turn bytes into a String and they disagree about failure: String(data:encoding:) returns nil on invalid UTF-8, String(decoding:as:) repairs it with U+FFFD and never tells you. Here's where broken bytes actually come from on iOS (chunked streams, Latin-1 files, BLE packets), how the repair corrupts hashes and signatures, Swift 6's String(validating:as:), and a chunk-safe decoder.

10 min read
A spreadsheet with rows and columns of numbers on a screen
Swift iOS Development

Swift's split() Throws Away Your Empty Fields. Your CSV Import Just Shifted Every Column Left.

Swift's split(separator:) omits empty subsequences by default, so a,,c becomes two fields, not three. Here's how that shifts CSV and TSV columns, why Windows CRLF line endings never split on a newline, how components(separatedBy:) differs, and the safe way to parse delimited lines.

8 min read
Rows of small wooden library card catalog drawers, each labeled for a range of the alphabet
Swift iOS Development

Your List Sorts "Track 10" Before "Track 2" and "Zebra" Before "apple". Swift's < Isn't Alphabetical.

Sorting user-facing strings with < in Swift compares Unicode scalar values: uppercase before lowercase, accented letters at the end, and numbers digit by digit. Here's how localizedStandardCompare, compare(options:locale:) and KeyPathComparator fix it, and when you should keep using <.

8 min read
A green car side mirror printed with the warning 'Objects in mirror are closer than they appear'
Swift iOS Development

One Invisible Character Makes Your App's Text Run Backwards. SE-0559 Finally Lets Swift See It.

U+202E RIGHT-TO-LEFT OVERRIDE can flip usernames, notification text, and file names like invoice_exe.pdf in any iOS app. Here's how bidi spoofing works, how to strip and isolate user text in Swift today, and what SE-0559's new Unicode.BidiClass adds.

10 min read
A yellow tape measure pulled out across a surface, its markings counting off units
Swift iOS Development

Your @Mention Highlight Drifts After Every Emoji. NSRange Doesn't Count What String.count Counts.

String.count counts characters, NSRange counts UTF-16 code units, and mixing them shifts every highlight, regex match, and text field limit after the first emoji. Here's why, and the two initializers that fix it.

9 min read
Close-up of a long stretch of string or rope
Swift Performance

Swift's String.count Isn't O(1). It Walks the Whole String Every Time.

Swift's String.count looks like a free property access, but it's not — Unicode-correct grapheme cluster counting makes it O(n). Here's why Swift made that trade, where it actually costs you, and the isEmpty habit that sidesteps most of it.

6 min read