ios-swiftui
SwiftUI: View, modifiers, @State/@Binding/@ObservedObject, @EnvironmentObject, animations, NavigationStack
What this skill does
# ios-swiftui
## Purpose
This skill provides expertise in SwiftUI for building declarative UIs in iOS apps, focusing on views, state management, animations, and navigation to streamline development.
## When to Use
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.
## Key Capabilities
- Create and modify views using structs that conform to the View protocol.
- Manage state with @State for local changes, @Binding for parent-child communication, @ObservedObject for external models, and @EnvironmentObject for app-wide data.
- Implement animations via withAnimation{} and modifiers like .animation(.easeIn).
- Handle navigation with NavigationStack, including stacks, lists, and sheets for multi-screen flows.
## Usage Patterns
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.
## Common Commands/API
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.
## Integration Notes
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.
## Error Handling
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.
## Concrete Usage Examples
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() }`.
## Graph Relationships
- Related to cluster: mobile (e.g., shares dependencies with android-kotlin skill).
- Links to: swift (for core language features), ios-core (for foundational iOS APIs).
- Dependencies: Requires xcode-tools for building; integrates with firebase-ios for backend services.
Related in General
modeling-omnistudio-epc-catalog
IncludedSalesforce Industries CME EPC product-modeling skill for Product2-based catalog creation. Use when creating EPC products, configuring product attributes, building offer bundles with Product Child Items, or reviewing EPC DataPack JSON metadata for product catalog changes. TRIGGER when: user creates or updates Product2 EPC records, AttributeAssignment payloads, AttributeMetadata/AttributeDefaultValues, Offer bundles, or ProductChildItem relationships. DO NOT TRIGGER when: designing OmniScripts/FlexCards/Integration Procedures (use building-omnistudio-omniscript, building-omnistudio-flexcard, or building-omnistudio-integration-procedure), implementing Apex business logic (use generating-apex), or troubleshooting deployment pipelines (use deploying-metadata).
relationship-science-coach
IncludedUse this skill for direct, practical adult relationship coaching: couples conflict, repair, trust, marriage, dating, flirting, attachment patterns, emotional connection, sex, desire differences, eroticism, kink negotiation, affection, love languages, breakups, and long-term passion. Draw on Gottman, EFT and Hold Me Tight, attachment science, modern sex research, Perel, Nagoski, Kerner, Schnarch, Love and Stosny, and flexible love-language tools. Be concrete and low-hedge. Redirect only for imminent danger, abuse, coercive control, minors, non-consent, self-harm, stalking, or medical/legal/psychiatric decisions.
building-sf-integrations
IncludedSalesforce integration architecture and runtime plumbing with 120-point scoring. Use this skill to set up Named Credentials, External Credentials, External Services, REST/SOAP callout patterns, Platform Events, and Change Data Capture. TRIGGER when: user sets up Named Credentials, External Services, REST/SOAP callouts, Platform Events, CDC, or touches .namedCredential-meta.xml files. DO NOT TRIGGER when: Connected App/OAuth config (use configuring-connected-apps), Apex-only logic (use generating-apex), or data import/export (use handling-sf-data).
venue-templates
IncludedAccess comprehensive LaTeX templates, formatting requirements, and submission guidelines for major scientific publication venues (Nature, Science, PLOS, IEEE, ACM), academic conferences (NeurIPS, ICML, CVPR, CHI), research posters, and grant proposals (NSF, NIH, DOE, DARPA). This skill should be used when preparing manuscripts for journal submission, conference papers, research posters, or grant proposals and need venue-specific formatting requirements and templates.
let-fate-decide
IncludedDraws the 12 Houses of the Zodiac Tarot spread to inject entropy into planning when prompts are vague, ambiguous, or casually delegated. Interprets the spread to guide next steps. Use when the user says 'let fate decide', 'YOLO', 'whatever', 'idk', or other nonchalant phrases, makes Yu-Gi-Oh references, or when you are about to arbitrarily pick between multiple reasonable approaches. Prefer over ask-questions-if-underspecified when the user's tone is casual or playful rather than precision-seeking.
net-ops
IncludedCross-platform network troubleshooting (Windows, macOS, Linux) via local or remote shell. Use for: DNS broken, can't resolve hostnames, nslookup/dig works but apps fail, NRPT, WFP, scutil, /etc/resolver, systemd-resolved, /etc/resolv.conf, NetworkManager, VPN DNS leak residue (ProtonVPN/Mullvad/WireGuard/AnyConnect), AV/firewall blocking DNS or DoH, Tailscale DNS interaction, intermittent connectivity, remote diagnostics over SSH.