SwiftUI

SwiftUI is Apple's declarative UI framework for building user interfaces across iOS, iPadOS, macOS, watchOS, tvOS, and visionOS. Introduced in 2019, SwiftUI uses Swift's strong type system and result builders to let developers describe the UI as a function of state; the framework diffs and renders updates automatically.

Core ideas

  • Declarative. Describe what the UI should look like; let the framework figure out the diffs and animations.
  • State-driven. Properties marked @State, @Binding, @StateObject, @ObservedObject, @Environment, @AppStorage trigger view updates.
  • Composable. Views are values; small reusable views compose into screens.
  • Cross-platform. The same view code can target multiple Apple platforms with platform-specific tweaks.
  • Previews. Xcode renders SwiftUI views in real time without running the app.

SwiftUI vs UIKit

  • SwiftUI. Declarative, less boilerplate, faster iteration; some edge cases still require dropping into UIKit.
  • UIKit. Imperative, mature, dominant in production codebases for the past 15 years.
  • Coexistence. SwiftUI views can host UIKit (and AppKit) and vice versa via UIViewRepresentable and UIHostingController.
🔗

Subscribe to Sahil's Playbook

Clear thinking on product, engineering, and building at scale. No noise. One email when there's something worth sharing.
[email protected]
Subscribe
Mastodon