swift_swiftui

SwiftUI framework concepts including property wrappers, state management, and reactive UI patterns.

Safety Notice

This listing is imported from skills.sh public index metadata. Review upstream SKILL.md and repository scripts before running.

Copy this and send it to your AI assistant to learn

Install skill "swift_swiftui" with this command: npx skills add swiftzilla/skills/swiftzilla-skills-swift-swiftui

SwiftUI

This skill covers SwiftUI framework concepts for building declarative user interfaces.

Overview

SwiftUI is Apple's modern declarative framework for building user interfaces across all Apple platforms using a reactive, state-driven approach.

Available References

Quick Reference

State Management Decision Tree

Need local mutable state?
├── YES → Is it a value type?
│   ├── YES → Use @State
│   └── NO → Use @StateObject
└── NO → Shared from parent?
    ├── YES → Is it value type?
    │   ├── YES → Use @Binding
    │   └── NO → Use @ObservedObject
    └── NO → Use @Environment

Property Wrappers

WrapperOwns DataData TypeUse For
@StateYesValue typeLocal UI state
@BindingNoValue typeShared state with parent
@ObservedObjectNoReference typeInjected dependencies
@StateObjectYesReference typeOwned view models
@EnvironmentNoAnyShared resources

Common Usage Patterns

// Local state
struct CounterView: View {
    @State private var count = 0
    
    var body: some View {
        Button("Count: \(count)") { count += 1 }
    }
}

// Shared state (parent to child)
struct ParentView: View {
    @State private var isOn = false
    
    var body: some View {
        ChildView(isOn: $isOn)
    }
}

struct ChildView: View {
    @Binding var isOn: Bool
    
    var body: some View {
        Toggle("Enable", isOn: $isOn)
    }
}

// Observable object
class ViewModel: ObservableObject {
    @Published var items: [Item] = []
}

struct ContentView: View {
    @StateObject private var viewModel = ViewModel()
    
    var body: some View {
        List(viewModel.items) { item in
            Text(item.name)
        }
    }
}

// Environment values
struct EnvironmentView: View {
    @Environment(\.colorScheme) var colorScheme
    @Environment(\.dismiss) var dismiss
    
    var body: some View {
        Text(colorScheme == .dark ? "Dark" : "Light")
    }
}

Best Practices

  1. Use @State for local UI state - Toggles, text fields, counters
  2. Lift state up when shared - Single source of truth
  3. Use @StateObject for owned view models - Survives view recreation
  4. Pass @Binding to child views - Two-way data flow
  5. Keep @State minimal - Only store what's needed for UI
  6. Use @Environment for system values - Color scheme, locale, etc.
  7. Access on main thread - All property wrappers require @MainActor
  8. Initialize with underscore - _count = State(initialValue:)

Common Pitfalls

PitfallSolution
Initializing @State directlyUse _property = State(initialValue:)
Creating @ObservedObject in initUse @StateObject instead
Mutating on background threadDispatch to main queue
Passing @State instead of BindingUse $property for Binding

For More Information

Visit https://swiftzilla.dev for comprehensive SwiftUI documentation.

Source Transparency

This detail page is rendered from real SKILL.md content. Trust labels are metadata-based hints, not a safety guarantee.

Related Skills

Related by shared tags or category signals.

General

swift_concurrency

No summary provided by upstream source.

Repository SourceNeeds Review
General

swift_style

No summary provided by upstream source.

Repository SourceNeeds Review
General

swift_combine

No summary provided by upstream source.

Repository SourceNeeds Review
General

swift_structure

No summary provided by upstream source.

Repository SourceNeeds Review