Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions swiftui-expert-skill/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ Consult the reference file for each topic relevant to the current task:
| macOS scenes | `references/macos-scenes.md` |
| macOS window styling | `references/macos-window-styling.md` |
| macOS views | `references/macos-views.md` |
| Text patterns | `references/text-patterns.md` |
| Deprecated API lookup | `references/latest-apis.md` |

## Correctness Checklist
Expand Down Expand Up @@ -100,3 +101,4 @@ These are hard rules -- violations are always bugs:
- `references/macos-scenes.md` -- Settings, MenuBarExtra, WindowGroup, multi-window
- `references/macos-window-styling.md` -- Toolbar styles, window sizing, Commands
- `references/macos-views.md` -- HSplitView, Table, PasteButton, AppKit interop
- `references/text-patterns.md` -- Text initializer selection, verbatim vs localized
32 changes: 32 additions & 0 deletions swiftui-expert-skill/references/text-patterns.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# SwiftUI Text Patterns Reference

## Table of Contents

- [Text Initialization: Verbatim vs Localized](#text-initialization-verbatim-vs-localized)

## Text Initialization: Verbatim vs Localized

**Default: always use `Text("…")`.** Only use `Text(verbatim:)` when explicitly required for a string literal that must not be localized.

```swift
// Localized literal - "Save" is used as the localization key and looked up in Localizable.strings (only if one exists in the project)
Text("Save")

// String variable - bypasses localization automatically; no verbatim needed
let filename: String = model.exportFilename
Text(filename)

// Non-localized literal - use verbatim only when the literal must not be localized
Text(verbatim: "pencil")
```

### Decision Flow

```
Is the input a String variable or dynamic value?
└─ YES → Text(variable) // bypasses localization automatically

Is the string literal intended for localization?
├─ YES → Text("…") // default; key looked up in Localizable.strings
└─ NO → Text(verbatim: "…") // only when explicitly non-localized
```