Docs
Text

Text DiffNew

Two versions of a text, word by word: removed words struck through in red, new ones underlined, with a clean view.

$npx swiftpieces add TextDiff
Free · MIT + Commons ClauseiOS 17.0+textdiffchangesairewritereviewaccessibility
Type
TextDiff
Files
TextDiff.swift
Depends on
Nothing (Apple frameworks only)
Version
1.0.0

Colors and type for TextDiff. .standard is the house palette.

Notes

  • Give it two versions of a text: TextDiff(from: draft, to: rewrite). It compares them word by word and keeps the spaces in place, so neighbouring words never run together.
  • In .changes mode, removed words are struck through in red and new words are underlined. A removal always comes before what replaced it, so "will try to will" reads in order.
  • Bind mode to a picker or a button: .clean folds the removed words away and drops the underlines, so it reads as the final text, and .original shows the text as it was. Switching animates with the morph spring.
  • TextDiff.changeCount(from:to:) counts the changes for a caption such as "Edited by AI · 3 changes". A removal and the words that replaced it count as one change.
  • VoiceOver reads the text with each change in place, such as "Our team, removed: will try to, added: will, reply…". In the other modes it reads the plain text.
  • The diff runs when the view is made, which is instant for paragraphs. For whole documents, show one paragraph per TextDiff.

Usage

TextDiffExample()

Install

Pick one. Run it from the folder that contains your .xcodeproj and the files land inside your app.

Terminal

$npx swiftpieces add TextDiff

Or ask your coding agent · Claude Code, Cursor or Xcode, once the MCP server is connected

>Add the SwiftPieces "Text Diff" piece to my app

Or copy the source above into your app.

New to SwiftUI?If you know React, CSS or Tailwind, SwiftUI is easier to pick up than it looks.Try real app patterns first

Building a whole app? See SwiftPieces Pro →

All text →

Build it yourself: SwiftUI animations guide · Liquid Glass guide

On this page

SwiftPiecesPro

Build the whole app with one library.

Production-ready screens, whole flows, complete app templates, a Build Kit your agent follows and Pro remixing.

Explore Pro