foundation-attributed-string

Create and mutate Foundation AttributedString instances with range-safe attribute application.

4|1|Updated Apr 2, 2026
One-click install
npx skills add https://github.com/AutisticAF/claude-code-apple-dev-plugin --skill foundation-attributed-string
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: foundation-attributed-string
Source: https://github.com/AutisticAF/claude-code-apple-dev-plugin/tree/main/skills/foundation-attributed-string
Command: npx skills add https://github.com/AutisticAF/claude-code-apple-dev-plugin --skill foundation-attributed-string

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Developers struggle to create, style, and safely mutate rich text using Foundation's AttributedString while handling version-gated APIs, paragraph formatting, selection editing, and non-contiguous ranges in Swift and SwiftUI projects. This skill consolidates correct API shapes, common pitfalls, and migration patterns so you can apply attributes, control layout, and integrate with TextEditor reliably.

Core Features & Use Cases

  • Provides idiomatic examples for initializing and mutating AttributedString values while respecting value-type semantics and safe range lookups.
  • Shows both legacy paragraph-style workflows and modern alignment, line-height, and writing-direction APIs with platform availability guidance.
  • Explains programmatic text selection and replacement, discontiguous substring manipulation, UTF-8 access, and SwiftUI TextEditor integration for rich text editing.
  • Use case: update a localized paragraph's alignment and line height, highlight multiple non-contiguous ranges, and replace the current selection with styled content while preserving selection semantics.

Quick Start

Use the foundation-attributed-string skill to convert a plain string into an AttributedString, apply font and color attributes to a specific range, set paragraph alignment, and prepare it for display or editing in SwiftUI.

Frequently Asked Questions about foundation-attributed-string

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I safely apply attributes to a specific range in a Swift AttributedString?

You can apply attributes to a Swift AttributedString by using range-safe mutations that respect value-type semantics, ensuring correct index lookups and safe attribute application when styling specific substrings.

What is the best way to set paragraph alignment and line height in SwiftUI TextEditor?

Setting paragraph alignment and line height in SwiftUI TextEditor requires modern APIs gated by iOS 26+/macOS 26+ availability checks, or legacy paragraph-style workflows for older OS versions to ensure correct text layout.

Can I highlight multiple discontiguous substrings within an AttributedString?

Yes, you can highlight discontiguous substrings within an AttributedString by manipulating non-contiguous ranges, allowing you to apply distinct attributes to multiple disjoint text selections simultaneously.

Does AttributedString support programmatic text selection replacement in Swift?

AttributedString supports programmatic text selection replacement in Swift through correct inout selection replacement semantics, ensuring styled content replaces the current selection while preserving range boundaries in SwiftUI TextEditor integration.

Why does my AttributedString paragraph style not apply correctly across different iOS versions?

AttributedString paragraph styles may fail across iOS versions because newer alignment, line-height, and writing-direction APIs require platform availability checks for iOS 26+/macOS 26+, whereas older versions need legacy paragraph-style fallbacks.

How do I control writing direction and accessibility for rich text in Swift?

To control writing direction and accessibility for rich text in Swift, apply modern writing-direction APIs with proper platform availability checks and incorporate accessibility considerations when preparing AttributedString instances for display or editing.