用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
直接命令不会经过审查 Prompt;运行前请先检查来源。
npx skills add https://github.com/G1Joshi/Agent-Skills --skill swiftui命令会保持在同一行。复制前请横向滚动并检查完整内容。
想先保存到本地?可下载 SkillsMP 当前能够提供的文件。
基于 SOC 职业分类
正在显示 SKILL.md
| name | swiftui |
| description | SwiftUI declarative Apple UI framework. Use for iOS/macOS. |
SwiftUI is Apple's declarative framework for building user interfaces across all Apple platforms (iOS, macOS, watchOS, tvOS, visionOS) with the power of Swift.
import SwiftUI
@main
struct MyApp: App {
var body: some Scene {
WindowGroup {
ContentView()
}
}
}
// Observation Framework (iOS 17+)
@Observable
class UserSettings {
var username = "Guest"
var isLoggedIn = false
}
struct ContentView: View {
@State private var settings = UserSettings()
var body: some View {
NavigationStack {
VStack(spacing: 20) {
Text("Hello, \(settings.username)!")
.font(.largeTitle)
Button("Log In") {
settings.username = "User"
settings.isLoggedIn = true
}
.buttonStyle(.borderedProminent)
NavigationLink("Settings", value: "settings")
}
.navigationDestination(for: String.self) { path in
if path == "settings" {
Text("Settings Page")
}
}
}
}
}
Instead of imperatively mutating UI views (like UIKit), you describe what the UI should look like for a given state. The system handles the updates.
@StateObject and @ObservedObject for cleaner data flow.Methods called on views that wrap the view and return a new view with the modification applied (e.g., .padding(), .background()). Order matters.
Replace NavigationView with NavigationStack for robust programmatic navigation.
.navigationDestination(for:) to decouple navigation logic from views.NavigationPath) in a model for deep linking support.Bind Views to ViewModels marked with @Observable. The View purely renders the state exposed by the ViewModel.
@Observable class ProfileViewModel {
var profile: Profile?
func loadProfile() async { /* ... */ }
}
Do:
Extract Subview).Environment for global dependencies (like themes or user session).Don't:
body property (it's computed frequently).AnyView unless absolutely necessary (kills performance/diffing).| Error | Cause | Solution |
|---|---|---|
Type '...' does not conform to protocol 'View' | The body property is missing or doesn't return some View. | Ensure var body: some View returns a valid view hierarchy. |
Modifying state during view update | Changing @State directly inside the body calculation. | Move side effects to .onAppear or buttons/actions. |
Trailing closure passed to parameter of type... | Syntax error in view builder structure. | Check braces {} and modifier placement. |