attributed-string

attributed-string is a skill for Claude Code, Codex from rshankras/claude-code-apple-skills. It costs 37 tokens per session (2,547 once invoked), scanned A, original, MIT.

A guide to AttributedString, Swift’s built-in type for text whose parts can have different formatting or behavior. It covers rich text, alignment, writing direction, line spacing, selection, editing, and SwiftUI integration.

In plain words
What is it for?
Use it to create or edit styled text, control paragraph layout, support text selection and editing, or display AttributedString values in SwiftUI TextEditor and other views.
Why use it?
It reduces mistakes when changing only selected parts of formatted text or connecting rich text to an editor. It also explains less familiar concepts such as a range set for multiple non-adjacent selections.

Skill for Claude CodeCodex

Part of the apple-skills plugin — 57 skills shipped together

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add skills/rshankras/claude-code-apple-skills/attributed-string
Any agent
npx skills add rshankras/claude-code-apple-skills --skill attributed-string
Clone the repo
git clone --depth 1 https://github.com/rshankras/claude-code-apple-skills

Made for: Claude Code, Codex.

Or install apple-skills, the plugin that ships this one along with the rest of its 57 skills.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for attributed-string

README.md
[![agentmods](https://agentmods.dev/badge/skills/rshankras/claude-code-apple-skills/attributed-string.svg)](https://agentmods.dev/skills/rshankras/claude-code-apple-skills/attributed-string)
Your own site
<a href="https://agentmods.dev/skills/rshankras/claude-code-apple-skills/attributed-string"><img src="https://agentmods.dev/badge/skills/rshankras/claude-code-apple-skills/attributed-string.svg" alt="Measured on agentmods" height="20"></a>
Per session 37 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 2,547 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00037 $0.02547
Opus 5 $0.00018 $0.01273
Sonnet 5 $0.00007 $0.00509
Haiku 4.5 $0.00004 $0.00255

Measured 4d ago against content hash 82c403a3ae62, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

attributed-string scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 4d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

skills/foundation/attributed-string/SKILL.md · 314 lines

How it starts

The opening of the file, as written. The whole thing — 314 lines — stays where its author put it; the contents beside it link to each section on GitHub.

AttributedString Patterns

Correct API shapes and patterns for Foundation's AttributedString. Covers creating styled text, applying attributes to ranges, text alignment, writing direction, line height control, text selection and editing, discontiguous substrings, and SwiftUI integration.

When This Skill Activates

Use this skill when the user:

  • Asks about AttributedString creation or manipulation
  • Wants to style text with fonts, colors, underlines, or other attributes
  • Mentions text alignment, writing direction, or line height
  • Asks about text selection or text editing with AttributedString
  • Wants to work with DiscontiguousAttributedSubstring or RangeSet
  • Mentions TextEditor with AttributedString in SwiftUI
  • Asks about rich text formatting in Swift
  • Wants to replace or modify text within an AttributedString
  • Mentions paragraphStyle, textSelectionAffinity, or AttributedTextSelection

Decision Tree

What do you need with AttributedString?
|
+-- Create or style text
|   |
|   +-- Simple inline attributes (font, color)
|   |   --> Creating and Styling section
|   |
|   +-- Paragraph-level formatting (alignment, line height)
|       --> Text Alignment and Formatting section
|
+-- Control text layout
|   |
|   +-- Writing direction (LTR / RTL)
|   |   --> Writing Direction and Line Height section
|   |
|   +-- Line spacing / height
|       --> Writing Direction and Line Height section
|
+-- Edit or select text programmatically
|   |
|   +-- Replace selection with characters or AttributedString
|   |   --> Text Selection and Editing section
|   |
|   +-- Work with multiple non-contiguous ranges
|       --> DiscontiguousAttributedSubstring section
|
+-- Display in SwiftUI
    --> SwiftUI Integration section

API Availability

API Minimum Version Notes
AttributedString iOS 15 / macOS 12 Swift-native replacement for NSAttributedString
AttributedString.paragraphStyle iOS 15 / macOS 12 Uses NSMutableParagraphStyle
AttributedString.writingDirection iOS 26 / macOS 26 New in 2025
AttributedString.LineHeight iOS 26 / macOS 26 .exact(points:), .multiple(factor:), .loose
AttributedString.alignment iOS 26 / macOS 26 .left, .center, .right
AttributedTextSelection iOS 26 / macOS 26 Programmatic text selection
replaceSelection(_:withCharacters:) iOS 26 / macOS 26 Replace selection with plain characters
replaceSelection(_:with:) iOS 26 / macOS 26 Replace selection with AttributedString
DiscontiguousAttributedSubstring iOS 26 / macOS 26 Non-contiguous range selections
AttributedString.utf8 iOS 26 / macOS 26 UTF-8 code unit view
TextEditor(text:selection:) with AttributedString iOS 26 / macOS 26 SwiftUI rich text editing
.textSelectionAffinity(_:) iOS 26 / macOS 26 Control cursor affinity at line boundaries

Read the full file on GitHub · 314 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 4d ago First seen · 314 lines · 37 tokens per session scan A 82c403a3ae62

Subscribe to this mod's changes

attributed-string is a skill published in the GitHub repository rshankras/claude-code-apple-skills (696 stars, last pushed 1mo ago), licensed MIT. It adds 37 tokens to every session and 2,547 once invoked, about $0.0002 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.