swiftui-core
4
总安装量
4
周安装量
#53233
全站排名
安装命令
npx skills add https://github.com/makgunay/claude-swift-skills --skill swiftui-core
Agent 安装分布
opencode
4
claude-code
4
codex
4
cursor
4
gemini-cli
3
github-copilot
3
Skill 文档
SwiftUI Core Patterns
Modern SwiftUI patterns for views, navigation, state, toolbars, and text editing.
Critical Constraints
- â
NavigationViewâ âNavigationSplitView(sidebar/detail) orNavigationStack(push/pop) - â
@StateObjectâ â@Statewith@Observableclasses (macOS 14+) - â
@ObservedObjectâ â direct property or@Bindablefor bindings - â
@EnvironmentObjectâ â@Environmentwith custom key - â
toolbar { }without IDs for customizable toolbars â âtoolbar(id:)withToolbarItem(id:) - â Old
.searchablewithout behavior â â Add.searchToolbarBehavior(.minimize)for space efficiency - â Plain
StringinTextEditorfor rich text â â UseAttributedStringbinding
Reference Index
| File | When to Use |
|---|---|
references/toolbars.md |
Customizable toolbars, search integration, spacers, transitions |
references/text-editing.md |
TextEditor + AttributedString, selection, formatting toolbar |
references/attributed-string.md |
AttributedString API, text alignment, line height, writing direction |
Navigation Patterns
Sidebar + Detail (macOS preferred)
NavigationSplitView {
List(selection: $selectedItem) {
ForEach(items) { item in
NavigationLink(value: item) { Label(item.name, systemImage: item.icon) }
}
}
.navigationTitle("Items")
} detail: {
if let selectedItem {
DetailView(item: selectedItem)
} else {
ContentUnavailableView("Select an item", systemImage: "sidebar.left")
}
}
Push Navigation (iOS preferred)
NavigationStack(path: $path) {
List(items) { item in
NavigationLink(value: item) { Text(item.name) }
}
.navigationDestination(for: Item.self) { item in
DetailView(item: item)
}
}
State Management Quick Reference
| Need | macOS 14+ / iOS 17+ | Older targets |
|---|---|---|
| View owns mutable state | @State |
@State (value) / @StateObject (object) |
| View receives object | plain property | @ObservedObject |
| View needs binding | @Bindable var model |
@ObservedObject var model |
| Shared via environment | @Environment(\.key) |
@EnvironmentObject |
| View-local value | @State private var |
@State private var |
Common Mistakes & Fixes
| Mistake | Fix |
|---|---|
NavigationView { } |
NavigationSplitView { } detail: { } or NavigationStack { } |
.toolbar { ToolbarItem { } } for customizable |
.toolbar(id: "myToolbar") { ToolbarItem(id: "action") { } } |
Using NavigationLink(destination:) |
Use NavigationLink(value:) + .navigationDestination(for:) |
TextField for rich text |
TextEditor(text: $attributedString, selection: $selection) |
.sheet(isPresented:) without transition |
Add .matchedTransitionSource + .navigationTransition(.zoom) |