CocoaCheerleaders
Hints, tips and code snippets for Swift and SwiftUI. Short, focused, and ready to paste into Xcode.
Latest tips
Automatic plurals with inflect: true
Text("^[\(count) item](inflect: true)") picks "1 item" or "2 items" for you, with no if statements and no plural rules of your own.
Format dates the reader's way 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.
Stop using String(format:) for money
Text(price, format: .currency(code:)) formats money for the reader's locale: symbol, separators and decimals included.
"5 minutes ago" and live countdowns in SwiftUI
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.