Best for
- Use when replacing legacy Formatter subclasses, designing reusable format APIs, using SwiftUI Text(_:format:), correcting availability, or testing user-facing formatted output across locales.
dpearson2699/swift-ios-skills/skills/swift-formatstyle/SKILL.md
Formats and parses locale-aware numbers, decimals, currencies, percentages, dates, durations, measurements, names, lists, byte counts, and URLs with Foundation FormatStyle and ParseableFormatStyle. Use when replacing legacy Formatter subclasses, designing reusable format APIs, using SwiftUI Text(_:format:), correcting availability, or testing user-facing formatted output across locales.
Decision brief
Use Foundation's type-safe FormatStyle APIs for user-facing display and ParseableFormatStyle when the same convention must accept input. Route String Catalogs, plurals, localized copy, bundles, and RTL layout to ios-localization; formatting still requires locale review even when…
Compatibility matrix
| Platform | Status | Evidence | What to check |
|---|---|---|---|
| Codex | Not declared | No explicit evidence | Portability before use |
| Claude Code | Not declared | No explicit evidence | Portability before use |
| Cursor | Not declared | No explicit evidence | Portability before use |
| Gemini CLI | Not declared | No explicit evidence | Portability before use |
Installation
The source command is displayed only when detected. A safe inspection prompt is always available so your agent can explain every action before execution.
npx skills add https://github.com/dpearson2699/swift-ios-skills --skill "skills/swift-formatstyle"Inspect the Agent Skill "swift-formatstyle" from https://github.com/dpearson2699/swift-ios-skills/blob/90c9573272531337962fbb3505036d61ed23389a/skills/swift-formatstyle/SKILL.md at commit 90c9573272531337962fbb3505036d61ed23389a. List every install step, command, network request, credential, file read/write, external action, and rollback step. Explain whether it fits my task. Do not install or execute anything until I approve.
Workflow
1. Identify the value's semantic type and whether output is display-only or must round-trip through parsing. 2. Select the narrowest built-in style and keep the user's current locale unless a wire format explicitly requires another locale. 3. Render the exact UI with representat…
[ ] Semantic value type and display-versus-parse requirement identified
Review the “Quick Reference” section in the pinned source before continuing.
Prefer FormatStyle over legacy NumberFormatter, DateFormatter, DateComponentsFormatter, and manual interpolation for new iOS 15+ code.
Use the matching parseable style when users edit or import formatted values:
Permission review
No configured static risk pattern was detected
This is not proof of safety. Runtime behavior, indirect dependencies, and hidden external systems are outside the static scan.
Evidence record
| Signal | Value | Evidence type | Meaning |
|---|---|---|---|
| Quality score | 78/100 | Computed | Documentation, specificity, maintenance, and trust rules |
| Repository stars | 933 | Source | Repository attention, not individual Skill quality |
| Compatibility | 0 platforms | Source | Declared in the catalog source record |
| Usage guide | automated source guide | Editorial | Generated or reviewed according to the visible evidence level |
Pinned source
Use Foundation's type-safe FormatStyle APIs for user-facing display and ParseableFormatStyle when the same convention must accept input. Route String Catalogs, plurals, localized copy, bundles, and RTL layout to ios-localization; formatting still requires locale review even when no text is translated.
en_US, de_DE, ar_SA, and ja_JP.Load FormatStyle Recipes when implementation needs concrete modifiers, date intervals, relative dates, duration patterns, measurements, names, lists, byte counts, or URL component controls.
| Value | Default style | Important constraint |
|---|---|---|
Int, Double | .number | Configure precision, rounding, grouping, notation, or sign only as required. |
Decimal | .number, .percent, .currency(code:) | Prefer for exact decimal display and parsing. |
| Currency | .currency(code:) | Pass an ISO 4217 code; never hardcode a symbol. |
| Percent | .percent | Confirm whether the input is a fraction (0.85) or whole percent (85). |
Date | .dateTime, .relative, .interval | Relative output should usually stand alone, not be embedded in a sentence. |
Duration | .time(pattern:), .units(allowed:width:) | Requires iOS 16+; choose compact clock output versus labeled units. |
Measurement | .measurement(width:usage:) | usage: controls locale-aware conversion policy. |
PersonNameComponents | .name(style:) | Do not manually concatenate name parts. |
| Collections | .list(type:width:) | Let locale rules choose separators and conjunctions. |
| Byte count | .byteCount(style:) | Choose file, memory, decimal, or binary semantics deliberately. |
URL | .url | Requires iOS 16+; query, port, and fragment are opt-in display components. |
FormatStyle over legacy NumberFormatter, DateFormatter, DateComponentsFormatter, and manual interpolation for new iOS 15+ code.Duration format styles and URL.FormatStyle require iOS 16+.Date.AnchoredRelativeFormatStyle requires iOS 18+ and formats relative to a fixed anchor rather than the current moment..locale(...) for normal UI so the style inherits the user's locale. Use a fixed locale only for an explicit protocol or test fixture.Docs: FormatStyle
Use the matching parseable style when users edit or import formatted values:
let style = Decimal.FormatStyle.Currency(code: "USD")
.locale(Locale(identifier: "en_US"))
let value = try Decimal("$3,500.63", format: style)
let display = value.formatted(style)
The fixed locale above is appropriate only because the input contract is explicitly en_US. For normal UI input, use the user's locale and test round trips with representative decimal separators, currency placement, calendars, and numbering systems.
Prefer Text(_:format:) so SwiftUI owns the formatted value:
Text(price, format: .currency(code: currencyCode))
Text(date, format: .dateTime.month().day().year())
Text(duration, format: .units(allowed: [.minutes, .seconds]))
For every user-facing formatted Text, preview or test the exact screen across the locale matrix. Use Text(.now, style: .timer), Text(.now, style: .relative), or Text(timerInterval:) for live-updating time displays rather than manually scheduling string refreshes.
Create a custom style only when built-in composition cannot express the domain convention. FormatStyle refines Codable and Hashable; keep styles as reusable values and add ParseableFormatStyle only when input must round-trip.
struct AbbreviatedCountStyle: FormatStyle {
func format(_ value: Int) -> String {
switch value {
case ..<1_000: "\(value)"
case 1_000..<1_000_000: String(format: "%.1fK", Double(value) / 1_000)
default: String(format: "%.1fM", Double(value) / 1_000_000)
}
}
}
extension FormatStyle where Self == AbbreviatedCountStyle {
static var abbreviatedCount: Self { .init() }
}
Custom styles still need locale and accessibility review; a compact English suffix may not be suitable for every locale.
| Mistake | Fix |
|---|---|
| Manual formatting or legacy formatter allocation in view code | Use the matching FormatStyle and Text(_:format:). |
| Hardcoded currency symbol or locale | Pass an ISO currency code and inherit the user locale unless the contract says otherwise. |
| Binary floating-point for exact decimal input | Use Decimal.FormatStyle and its matching parse strategy. |
Assuming URL.formatted() preserves every component | Opt in to .port(.always), .query(.always), or .fragment(.always) only when those components should display. |
| Relative date output embedded in a larger sentence | Keep it standalone or localize the complete sentence. |
| Clock-style duration used for prose | Use .units(allowed:width:) for labeled output. |
| Measurement conversion left implicit | Select a usage: appropriate to the UI. |
| One-locale spot check | Run the same exact-screen fixture across representative locales and fix/rerun failures. |
FormatStyle used where it can express the conventionDecimalusage: are deliberateText(_:format:) for formatted valuesAlternatives
event4u-app/agent-config
Use when the user says "review the design", "check the UI", or wants a comprehensive UI/UX review. Uses a 7-phase methodology covering interaction, responsiveness, accessibility, and more.
event4u-app/agent-config
Use when writing, generating, or improving Pest tests for Laravel — clear intent, good coverage, maintainable structure, and alignment with project testing conventions.
affaan-m/ECC
Test-driven development for Quarkus 3.x LTS using JUnit 5, Mockito, REST Assured, Camel testing, and JaCoCo. Use when adding features, fixing bugs, or refactoring event-driven services.
github/awesome-copilot
Expert-level Windows batch file (.bat/.cmd) skill for writing, debugging, and maintaining CMD scripts. Use when asked to "create a batch file", "write a .bat script", "automate a Windows task", "CMD scripting", "batch automation", "scheduled task script", "Windows shell script", or when working with .bat/.cmd files in the workspace. Covers cmd.exe syntax, environment variables, control flow, string processing, error handling, and integration with system tools.