/swift-formatstyle
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,
$ npx -y skills add dpearson2699/swift-ios-skills --skill swift-formatstyle --agent claude-codeHow it fires
How this skill gets triggered: by you, by Claude, or both.
- Fires itselfAuto-invocation. Claude auto-loads it when your prompt matches the work.Auto-invocation is when the right skill fires by itself at the right moment, driven by a FLOW.md router and a hook, instead of you invoking it by name. It is the difference between a skill being installed and a skill actually getting used.Read the full definition →
- You can call itInvoke it directly when you want it.
- Slash command
/swift-formatstyle
Context preview
The summary Claude sees to decide when to auto-load this skill.
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,
SKILL.md
swift-formatstyle.SKILL.mdname: swift-formatstyle
description: "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."
Swift FormatStyle
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.
Contents
- [Workflow](#workflow)
- [Quick Reference](#quick-reference)
- [Selection and Availability](#selection-and-availability)
- [Parsing](#parsing)
- [SwiftUI Integration](#swiftui-integration)
- [Custom FormatStyle](#custom-formatstyle)
- [Common Mistakes](#common-mistakes)
- [Review Checklist](#review-checklist)
- [References](#references)
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 representative locales such as `en_US`, `de_DE`, `ar_SA`, and `ja_JP`. 4. Check separators, numbering systems, calendars, currency and unit conventions, text direction, and layout. 5. If output or parsing fails, fix the style or surrounding copy, restore the input fixture, and rerun the same locale matrix.
Load [FormatStyle Recipes](references/formatstyle-recipes.md) when implementation needs concrete modifiers, date intervals, relative dates, duration patterns, measurements, names, lists, byte counts, or URL component controls.
Quick Reference
| 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. |
Selection and Availability
- Prefer `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.
- Omit `.locale(...)` for normal UI so the style inherits the user's locale. Use a fixed locale only for an explicit protocol or test fixture.
- Treat relative date output as standalone text unless the entire sentence is localized around it.
Docs: [FormatStyle](https://sosumi.ai/documentation/foundation/formatstyle)
Parsing
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.
SwiftUI Integration
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.
Custom FormatStyle
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.
Common Mistakes
| 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
Read more
name: swift-formatstyle description: "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."
Swift FormatStyle
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.
Contents
- [Workflow](#workflow)
- [Quick Reference](#quick-reference)
- [Selection and Availability](#selection-and-availability)
- [Parsing](#parsing)
- [SwiftUI Integration](#swiftui-integration)
- [Custom FormatStyle](#custom-formatstyle)
- [Common Mistakes](#common-mistakes)
- [Review Checklist](#review-checklist)
- [References](#references)
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 representative locales such as `en_US`, `de_DE`, `ar_SA`, and `ja_JP`. 4. Check separators, numbering systems, calendars, currency and unit conventions, text direction, and layout. 5. If output or parsing fails, fix the style or surrounding copy, restore the input fixture, and rerun the same locale matrix.
Load [FormatStyle Recipes](references/formatstyle-recipes.md) when implementation needs concrete modifiers, date intervals, relative dates, duration patterns, measurements, names, lists, byte counts, or URL component controls.
Quick Reference
| 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. |
Selection and Availability
- Prefer `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.
- Omit `.locale(...)` for normal UI so the style inherits the user's locale. Use a fixed locale only for an explicit protocol or test fixture.
- Treat relative date output as standalone text unless the entire sentence is localized around it.
Docs: [FormatStyle](https://sosumi.ai/documentation/foundation/formatstyle)
Parsing
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.
SwiftUI Integration
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.
Custom FormatStyle
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.
Common Mistakes
| 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
86 agent skills optimized for iOS 26+ development with Swift 6.3 and modern Apple frameworks.
Repo: dpearson2699/swift-ios-skills
Other skills on swift-ios-skills.
- /accessorysetupkit
Discover and configure Bluetooth and Wi-Fi accessories using AccessorySetupKit. Use when presenting a privacy-preserving accessory picker, defining discovery descriptors for BLE or Wi-Fi devices, handling accessory session events, migrating from CoreBluetooth permission-based
Open skill - /activitykit
Implement, review, or improve Live Activities and Dynamic Island experiences in iOS apps using ActivityKit. Use when building real-time updating widgets for the Lock Screen and Dynamic Island — delivery tracking, sports scores, ride-sharing status, workout timers, media
Open skill - /adattributionkit
Measure ad effectiveness with privacy-preserving attribution using AdAttributionKit. Use when registering ad impressions, handling attribution postbacks, updating conversion values, implementing re-engagement attribution, configuring publisher or advertiser apps, or replacing
Open skill - /alarmkit
Implement AlarmKit alarms and countdown timers for iOS and iPadOS with Lock Screen, Dynamic Island, StandBy, and paired Apple Watch system UI. Covers AlarmManager scheduling, AlarmAttributes and AlarmPresentation, system Stop and AlarmButton secondary actions, authorization,
Open skill - /app-clips
Build iOS App Clips with invocation URLs, App Clip Codes, NFC, QR codes, Safari banners, Maps, Messages, target setup, App Store Connect experiences, size/capability constraints, NSUserActivity routing, SKOverlay promotion, App Group/keychain handoff, ephemeral notifications,
Open skill - /app-intents
Implement App Intents for Siri, Shortcuts, Spotlight, widgets, Control Center, and Apple Intelligence on iOS. Covers AppIntent actions, AppEntity and EntityQuery models, AppShortcutsProvider phrases, IndexedEntity Spotlight indexing, WidgetConfigurationIntent, SnippetIntent, and
Open skill

