Views, state, bindings, and navigation—build iOS interfaces the SwiftUI way.
SwiftUI is Apple’s declarative framework for iOS, macOS, and more. Here’s how to use it effectively.
SwiftUI and declarative iOS
Concepts
Views — Structs conforming to View; return a body (one view or a container like VStack, HStack, List). Use modifiers to customize.
State — @State for local view state; @StateObject for owned observable objects; @ObservedObject for passed-in objects. Changes trigger redraws. Use @Binding for two-way binding.
Navigation — NavigationStack (iOS 16+), NavigationLink. Sheets and fullScreenCover for modals. Use navigationDestination for programmatic push.
Data — Use async/await or Combine with ViewModel-like objects. Fetch in .task or on appear; store in @StateObject.
SwiftUI adoption (iOS projects):
SwiftUI in new iOS projects (%)
Best practices
Keep views small; extract subviews. Use @StateObject for view-owned state; pass @ObservedObject or environment for shared state. Prefer native components; wrap UIKit with UIViewRepresentable when needed.
SwiftUI in 100 seconds:
Takeaway
SwiftUI is the future of Apple UI. Learn state and layout first; then navigation and data. Use it for new iOS (and optionally macOS) apps; mix with UIKit where necessary.