skillfed

swift-format-style

This skill guides you through adopting Swift's modern FormatStyle APIs for formatting values across numbers, dates, durations, measurements, and other types. It identifies legacy patterns like DateFormatter and C-style String(format:) calls, then shows you how to replace them with contemporary .formatted() methods and FormatStyle configurations. Perfect for modernizing iOS 15+ codebases.

swift-format-style teaches you to use modern FormatStyle APIs instead of legacy Formatter subclasses for all value formatting needs.

AI-generated summary based on this skill's SKILL.md

7 0 MIT updated by n0an

Install

n0an/Swift-FormatStyle-Agent-Skill/swift-format-style

CLI (skillfed)coming soon
git clone https://github.com/n0an/Swift-FormatStyle-Agent-Skill
cp -r Swift-FormatStyle-Agent-Skill/swift-format-style ~/.claude/skills/swift-format-style

Frequently asked questions

AI-generated answers based on this skill's SKILL.md and metadata

How do I use FormatStyle in Swift to replace legacy formatters?

swift-format-style teaches you to adopt modern FormatStyle APIs instead of legacy Formatter subclasses. Replace DateFormatter, NumberFormatter, and similar classes with .formatted() methods on your values. For example, use `date.formatted(.dateTime.year().month().day())` instead of instantiating DateFormatter. FormatStyle is type-safe, Codable, and Hashable—making it ideal for iOS 15+ apps.

What are the best practices for swift currency formatting?

swift-format-style covers locale-aware currency formatting through FormatStyle. Use `.formatted(.currency(code: "USD"))` on Decimal or Double values to get proper symbol, grouping, and decimal placement. FormatStyle automatically respects the user's locale settings, eliminating manual currency symbol handling. This approach is safer and more maintainable than building format strings by hand.

How do I migrate from C-style String(format:) to .formatted() methods?

swift-format-style shows how to replace C-style String(format:) calls with modern .formatted() syntax. Instead of `String(format: "%.2f", value)`, use `value.formatted(.number.precision(.fractionLength(2)))`. The .formatted() API is type-checked at compile time, supports SwiftUI Text views natively, and eliminates format-string bugs. This skill guides you through common migration patterns.

Can swift-format-style help with FormatStyle date time formatting?

Yes. swift-format-style provides comprehensive guidance on date and time formatting with FormatStyle. Use `.formatted(.dateTime.year().month().day().hour().minute())` to customize output, or choose presets like `.dateTime.abbreviated`. FormatStyle handles locale-aware formatting automatically, replacing DateFormatter entirely for most use cases on iOS 15+.

How do I integrate FormatStyle with SwiftUI Text views properly?

swift-format-style explains how to use the `format:` parameter in SwiftUI Text views. Pass a FormatStyle directly: `Text(date, format: .dateTime.year().month().day())`. This approach is more efficient than calling .formatted() separately and keeps formatting logic declarative within your view hierarchy.

What does swift-format-style cover for modern number formatting?

swift-format-style guides you through modern number formatting with FormatStyle, including integers, decimals, percentages, and byte counts. Use `.formatted(.number.precision(.fractionLength(2)))` for decimals or `.formatted(.byteCount(style: .file))` for file sizes. These APIs replace NumberFormatter and provide compile-time safety with automatic locale adaptation.

SKILL.md

rendered from the published skill — quoted content, verbatim

Write and review Swift code that formats values for display, ensuring modern FormatStyle APIs are used instead of legacy Formatter subclasses or C-style formatting.

Review process:

  1. Check for legacy formatting patterns and replace with modern FormatStyle equivalents using references/anti-patterns.md.
  2. Validate number, percent, and currency formatting using references/numeric-styles.md.
  3. Validate date and time formatting using references/date-styles.md.
  4. Validate duration formatting using references/duration-styles.md.
  5. Validate measurement, list, person name, byte count, and URL formatting using references/other-styles.md.
  6. Check SwiftUI Text views for proper FormatStyle integration using references/swiftui.md.

If doing partial work, load only the relevant reference files.

Core Instructions

  • Target iOS

(truncated - see the full file via the links below)

Read as markdown · JSON record · Browse the source repository

File tree — 8 files
swift-format-style/SKILL.md
swift-format-style/agents/openai.yaml
swift-format-style/references/anti-patterns.md
swift-format-style/references/date-styles.md
swift-format-style/references/duration-styles.md
swift-format-style/references/numeric-styles.md
swift-format-style/references/other-styles.md
swift-format-style/references/swiftui.md

Related skills

Tags

api-modernization swift-formatting legacy-deprecation locale-aware-output type-safe-formatting swiftui-integration code-review-guide ios-15-plus