Docs
Text

Match HighlightNew

Search results that mark why they matched, on a red mark that grows as you type, ignoring case and accents.

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

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

Notes

  • Use it for each result in a search list: MatchHighlight(recipe.title, query: search). The part of each word that matches sits on a red mark, with the text in dark ink on it.
  • Matching ignores case, accents and full-width forms, in the reader's locale: "pate" marks all four letters of "Pâté", and "CAFE" marks "café".
  • Each word of the query is matched on its own, at the start of any word, so "pasta spicy" marks both words of "Spicy pasta bake". Set mode: .anywhere to match inside words too, for codes, file names and IDs.
  • Filter your list with MatchHighlight.matches(_:query:). It uses the same rules as the marks, so a row is shown exactly when every query word has a mark in it.
  • The marks grow and shrink with the value spring as the query changes, and an empty query marks nothing.
  • VoiceOver reads the plain text without the marks.

Usage

MatchHighlightExample()

Install

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

Terminal

$npx swiftpieces add MatchHighlight

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

>Add the SwiftPieces "Match Highlight" 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