CocoaCheerleaders
Hints, tips and code snippets for Swift and SwiftUI. Short, focused, and ready to paste into Xcode.
Latest tips
Join lists naturally, in any language
Turn an array of word into a sentence with the right commas and the right word for "and" or "or", without string joining.
Format percentages and decimal places
Format percentages, signs, and decimal places with format styles, and let the guest's locale choose the separators.
Compact big numbers like 1.2K and 3.4M
Show follower counts, views and downloads in short form, with the right abbreviations for each language.
Automatic plurals with inflect
1 fish, 2 fish—pluralization is weird. A quick way to automatically get grammar-compliant plurals for things other than fish.
Format dates with Date.FormatStyle
Ask for the date fields you want and let the locale decide the order, separators and 12 or 24-hour clock. No more dateFormat strings.
Formatting money
How to format money for the guest's locale: symbol, separators and decimals included.
"5 minutes ago" and live countdowns
Text can show relative dates and run timers by itself. No Timer, no publishers, no string building.
By category
Formatting
Numbers, currency, percentages, dates, relative time, durations, measurements and lists, formatted the right way.
Text and localization
AttributedString, Markdown in Text, automatic grammar agreement and string catalogs.