apple-text-storage

Implement TextKit 1 and 2 storage backends with NSTextStorage subclassing patterns.

Updated Mar 19, 2026
One-click install
npx skills add https://github.com/sitapix/apple-text --skill apple-text-storage
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: apple-text-storage
Source: https://github.com/sitapix/apple-text/tree/main/skills/apple-text-storage
Command: npx skills add https://github.com/sitapix/apple-text --skill apple-text-storage

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

TextKit storage layers can be difficult to design and debug. This guide clarifies the architecture and lifecycle of NSTextStorage, NSTextContentStorage, and NSTextContentManager, including how they interact and how to reason about backing stores.

Core Features & Use Cases

  • Understand TextKit 1 and 2 storage models (backing stores, elements, and layout callbacks)
  • Learn subclassing NSTextStorage, implementing the editing lifecycle (beginEditing/edited/processEditing) and maintaining string/attributes consistency
  • Bridge to NSTextContentStorage and NSTextContentManager, including paragraph element generation and content synchronization
  • Apply best practices for batching edits, thread-safety, and common pitfalls like changeInLength correctness

Quick Start

Start by reviewing the storage architecture and implement a minimal NSTextStorage subclass with proper edited calls.

Frequently Asked Questions about apple-text-storage

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

FAQPage Schema
How do I subclass NSTextStorage to use a custom backing store like a piece table?

To subclass NSTextStorage for a custom backing store, implement the editing lifecycle by calling beginEditing, edited:range:changeInLength:, and processEditing to ensure safe mutation reporting and maintain string and attribute consistency.

How does NSTextContentStorage synchronize paragraph elements with the content manager?

NSTextContentStorage bridges to NSTextContentManager by generating paragraph elements and synchronizing content across storage and content manager interfaces, ensuring consistent regeneration of the element tree during text updates.

What is the correct editing lifecycle for NSTextStorage mutations?

The NSTextStorage editing lifecycle requires batching edits within beginEditing and processEditing calls, maintaining correct changeInLength values to avoid common pitfalls and ensure thread-safe text storage mutations.

How do I implement TextKit 2 storage with a CRDT backend?

Implementing TextKit 2 storage with a CRDT backend requires subclassing NSTextContentStorage and related delegates, applying transaction patterns to ensure safe mutation reporting and consistent element tree regeneration across interfaces.

Why is changeInLength incorrect when batching NSTextStorage edits?

Incorrect changeInLength during NSTextStorage batching usually stems from mismatched length deltas between the edited range and the backing store, causing inconsistent attribute state; apply proper transaction patterns to resolve this.