diff --git a/swiftui-expert-skill/SKILL.md b/swiftui-expert-skill/SKILL.md index f12241c..811840c 100644 --- a/swiftui-expert-skill/SKILL.md +++ b/swiftui-expert-skill/SKILL.md @@ -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 @@ -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 diff --git a/swiftui-expert-skill/references/text-patterns.md b/swiftui-expert-skill/references/text-patterns.md new file mode 100644 index 0000000..19fd5a3 --- /dev/null +++ b/swiftui-expert-skill/references/text-patterns.md @@ -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 +```