Mobile
SwiftUI
Apple's declarative UI framework for iOS, macOS, watchOS, tvOS and visionOS in Swift.
What it is
Apple introduced SwiftUI in 2019 as a modern replacement for UIKit and AppKit. You describe what the interface looks like for the current state, and the system updates the screen when data changes.
The UI is made of Views and modifiers: Text("Hi").font(.title).padding(). State is managed through property wrappers (@State, @Binding, @Observable, @Environment). One codebase adapts to different Apple platforms.
SwiftUI sits on native APIs, so it interoperates with UIKit where older or rare components are needed. The framework is closed source and runs only on Apple platforms.
Use it when
- A new app exclusively for Apple platforms.
- You need widgets, Live Activities, watchOS or visionOS, where SwiftUI is the main approach.
- You want less code and live Previews in Xcode.
Avoid it when
- You must support very old iOS versions: some APIs are unavailable.
- One codebase for iOS and Android: Flutter or React Native fit better.
- Very complex custom tables and collections where UIKit gives more control.
Key concepts
- View protocol
- Every UI element is a struct that conforms to
Viewand has abody. - Modifiers
- A chain of methods that change the look:
.padding(),.foregroundStyle(). - State and Binding
@Stateowns a value,@Bindinggives a child two-way access.- Observation
- An
@Observablemodel automatically updates only the Views that read it. - Previews
- A live screen preview in Xcode without a full run.
Example
Interview questions
1. How does SwiftUI differ from UIKit?
SwiftUI is declarative: you describe UI as a function of state. UIKit is imperative: you create and mutate objects by hand. SwiftUI is shorter, UIKit gives more low-level control.
2. How does @State differ from @Binding?
@Stateis a source of truth owned by the View.@Bindingis a reference to someone else's state that lets a child View read and change it.3. Why is a SwiftUI View a struct?
Structs are lightweight and immutable, so SwiftUI can create them often and compare them for updates. State lives separately in property wrappers.
4. How do you combine SwiftUI with UIKit?
Wrap UIKit in SwiftUI with
UIViewRepresentableandUIViewControllerRepresentable, and embed SwiftUI in UIKit withUIHostingController.
Related technologies
Logos belong to their owners and are used for identification only. Icons: Simple Icons (CC0), Devicon (MIT).