Swiftui
36 bites tagged Swiftui — interview questions with model answers, and 60-second explainers.
NavigationStack: Programmatic Navigation in SwiftUI
Think of NavigationStack as a pile of views. You push new views onto the stack programmatically by appending to a path array. This is SwiftUI's modern, data-driven way to handle deep navigation, replacing the older, buggier `NavigationView`.
TabView: SwiftUI's Built-in Tab Bar
TabView lets you show different views in the same space, switched by a tab bar. It's the standard for top-level app navigation, like switching between "Home," "Search," and "Profile." The footgun is nesting them; they are for main sections only.
MVVM: Separate SwiftUI Logic from Layout
MVVM separates logic from layout by moving state and business logic out of your SwiftUI View into a dedicated ViewModel class. This makes your code cleaner, more organized, and easier to test.
UIViewRepresentable: Bridging UIKit and SwiftUI
UIViewRepresentable is an adapter that lets you use battle-tested UIKit views inside your modern SwiftUI code. Use it for components like WKWebView that lack a native SwiftUI equivalent.
ObservableObject: Making Data Drive SwiftUI Views
ObservableObject lets your custom data classes signal SwiftUI views to refresh when data changes. Use it for reference types like a user profile or settings manager. Changes are ignored unless you mark properties with `@Published`, leaving your UI stale.
UIHostingController: Bridge SwiftUI into UIKit Apps
UIHostingController is an adapter that lets you use modern SwiftUI views inside a UIKit app by wrapping them in a UIViewController. This is key for migrating apps to SwiftUI or embedding new components.
SwiftUI List: More Than Just a Table View
A SwiftUI List is a declarative container for scrollable rows of data, like a modern UITableView. Use it for settings, feeds, or contact lists. The footgun: never nest a List inside a ScrollView, as it breaks scrolling behavior.
SwiftUI Modifiers: Stacking Changes on Views
Think of SwiftUI modifiers as non-destructive filters you apply to a view, creating a new, wrapped version with the change applied. You use them to add padding, set fonts, or handle taps. The footgun: modifier order matters immensely.
SwiftUI State and Binding: Owning vs. Sharing Data
In SwiftUI, `@State` is owning the data, while `@Binding` is borrowing a key. A view uses `@State` for its private source of truth, like a toggle's status, and passes a `@Binding` to child views so they can modify the original source.
SwiftUI Stacks: Arrange Views Vertically, Horizontally, and in Layers
SwiftUI stacks are your core layout tools for arranging views. Use VStack for vertical columns, HStack for horizontal rows, and ZStack for layering. They're essential for any UI, from simple rows to complex overlays.
SwiftUI's View: A Blueprint, Not a Building
A SwiftUI View is a lightweight blueprint for a piece of your UI, not the UI element itself. It's used to compose everything from a single button to an entire screen. The common mistake is treating it like a heavy `UIView` class; it's a cheap.
SwiftUI Theming with the Environment
Treat SwiftUI's Environment as a cascading style sheet for your app. You define design tokens like colors and fonts once at the top, and all child views automatically inherit them. This is key for building design systems or multi-brand apps.
Get Swiftui bites daily.
Five a day, five minutes, offline. With quizzes so it sticks.
Open testing — you’ll join as an early tester.