skills/mobile/ios-swiftui/SKILL.md
SwiftUI: View, modifiers, @State/@Binding/@ObservedObject, @EnvironmentObject, animations, NavigationStack
npx skillsauth add alphaonedev/openclaw-graph ios-swiftuiInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
This skill provides expertise in SwiftUI for building declarative UIs in iOS apps, focusing on views, state management, animations, and navigation to streamline development.
Use this skill for iOS projects requiring responsive interfaces, such as apps with dynamic content, user interactions, or complex navigation; ideal for new iOS apps (iOS 13+), prototyping, or migrating from UIKit.
To build a SwiftUI view, define a struct conforming to View and use modifiers in the body; for state, wrap variables with @State and update via functions. Pattern: Use @EnvironmentObject for shared data by injecting via .environmentObject() in the app's root view. For lists, apply List{} with ForEach{} for dynamic content. Always preview views with #Preview{} for rapid iteration. To handle sheets, use .sheet(isPresented: $isShowing) {} on a View.
Use @State for local state: @State private var count: Int = 0 then increment with Button("Tap") { count += 1 }.
Apply modifiers like .padding() or .foregroundColor(.blue) directly on views, e.g., Text("Hello").padding().background(.yellow).
For animations, wrap changes: withAnimation { self.isAnimating.toggle() } on a view with .animation(.default).
Navigation example: NavigationStack { List(items, id: \.id) { item in NavigationLink { DetailView(item: item) } } }.
Config format: In Xcode, ensure SwiftUI is selected in project settings; import SwiftUI in files.
Integrate SwiftUI into an existing iOS project by adding a SwiftUI view to a UIKit app via UIHostingController; set up in code like let hostingController = UIHostingController(rootView: MySwiftUIView()). For app-wide objects, pass via .environmentObject() in the @main App struct, e.g., @main struct App: App { var body: some Scene { WindowGroup { ContentView().environmentObject(MyModel()) } } }. If API keys are needed (e.g., for networking), load from env vars like let apiKey = ProcessInfo.processInfo.environment["MY_API_KEY"] and handle in your observed objects. Ensure iOS deployment target is 13.0+ in Xcode project settings.
Handle state-related errors by ensuring @State updates occur on the main thread; use DispatchQueue.main.async for async updates, e.g., DispatchQueue.main.async { self.data = newData }. For navigation issues, check NavigationStack paths and use .onAppear{} to validate state, e.g., onAppear { if path.isEmpty { path.append("home") } }. Common errors: "Cannot use instance member" – fix by making variables @State; log errors with print() or os_log for debugging. If bindings fail, verify the wrapped value is correctly passed, e.g., in child views.
Example 1: Simple counter view – Create a view with @State: struct CounterView: View { @State var count: Int = 0 var body: some View { VStack { Text("Count: \(count)") Button("Increment") { count += 1 } } } }. Use in app: ContentView().environment(\.colorScheme, .dark).
Example 2: Navigation with list – Build a list view: struct ItemList: View { @State var items = [1,2,3] var body: some View { NavigationStack { List(items, id: \.self) { item in Text("Item \(item)") } .navigationTitle("Items") } } }. Integrate by presenting: ItemList().sheet(isPresented: $showSheet) { DetailView() }.
tools
Root web development: project structure, tooling selection, deployment decisions
development
WebAssembly: Rust/Go/C to WASM, wasm-bindgen, Emscripten, WASM Component Model
development
Vue 3: Composition API script setup, Pinia, Vue Router 4, SFCs, Vite, Nuxt 3
tools
Tailwind CSS 4: utility classes, config, JIT, arbitrary values, darkMode, plugins, shadcn/ui