skip to content

For a new iOS screen, how do you choose between SwiftUI and UIKit, and when is dropping to UIKit inside SwiftUI justified?

level: seniorimportance: should knowfreq 65%

answer

  1. describe versus create and mutate
  2. deployment target gates newer APIs
  3. a capability SwiftUI lacks
  4. bridges work in both directions

basics

~20 s

Default to SwiftUI when its APIs at your deployment target cover the screen, since it removes manual update code. Use UIKit, or wrap a UIKit view, when you need an API or control SwiftUI lacks at that target.

solid answer

~40 s

The models differ: in SwiftUI a screen is a description derived from state and the framework applies changes, while in UIKit I create view objects and mutate them myself. For a new screen I default to SwiftUI — less update code, previews, one model across Apple platforms — as long as what I need exists at the app's deployment target, because SwiftUI APIs ship with OS releases: an app deploying to iOS 17 has `scrollPosition(id:anchor:)` but must gate `Tab`, which arrived in iOS 18. I choose UIKit, or wrap a UIKit view with `UIViewRepresentable` or `UIViewControllerRepresentable`, when the screen needs a capability or control SwiftUI doesn't offer at that target, or when it sits inside a large UIKit flow, where `UIHostingController` lets me adopt SwiftUI screen by screen instead.

go deeper

for a junior

Recall the core difference: SwiftUI describes UI from state, UIKit creates view objects you update yourself, and each can host the other.

for a middle

Explain how the deployment target limits which SwiftUI APIs you can use, and that bridges in both directions let the choice be made per component.

for a senior

Give a decision method for a specific screen: deployment target, missing capabilities, the surrounding UIKit flow and measured performance, with bridging to decide per component.

for a principal

Connect the per-screen choice to a migration plan: which flows move first, what the deployment-target policy is, and how the team keeps UIKit skills while adopting SwiftUI.

## Two models of building UI The comparison interviewers want starts with the model, not with a feature list. In **SwiftUI** a screen is a description derived from state: you declare views, SwiftUI reads their `body` when data changes and applies the difference. In **UIKit** you create view objects, keep references to them and mutate them as conditions change; Apple's documentation describes that imperative approach as putting the burden on controller code to instantiate, lay out, configure and continually update views. | Aspect | SwiftUI | UIKit | |---|---|---| | What you write | Value descriptions in `body` | View objects you create and keep | | Updating the screen | SwiftUI updates affected parts | Your code mutates each view | | Where API arrives | With each OS release's SwiftUI | Long-established, broad API surface | | Mixing | Hosts UIKit through representables | Hosts SwiftUI through hosting controllers | ## Why SwiftUI is the usual default for new screens - **Less update code.** State changes drive the screen, which removes the class of bugs where one update path is forgotten. - **One model across Apple platforms.** Most views and modifiers are shared across iPhone, iPad, Mac, Apple Watch, Apple TV and Apple Vision Pro, with platform-specific differences where needed. - **Text styles scale with Dynamic Type.** Fonts such as `.body` or `.headline` follow the user's text size setting without extra code. - **Fast iteration.** `#Preview` declarations render a screen in several states without navigating to it in the running app. - **Composability.** Small view structs are cheap to extract and reuse. ## When UIKit is the better choice The decision is concrete, not ideological. Ask these questions about the specific screen: 1. **Does the API exist at your deployment target?** SwiftUI APIs ship with OS releases. An app deploying back to iOS 17 can use `NavigationStack` (iOS 16) and `scrollPosition(id:anchor:)` (iOS 17), but `Tab` arrived in iOS 18 and needs an availability check or a fallback. If the screen depends on behaviour SwiftUI only gained later, UIKit may be the practical tool today. 2. **Do you need a capability or level of control SwiftUI doesn't expose?** When a screen needs a UIKit component's behaviour that has no SwiftUI equivalent at your target, use UIKit for that piece. 3. **Where does the screen live?** A screen deep inside a large UIKit navigation flow, owned by a team fluent in UIKit, may be cheaper to build in UIKit now and port later. 4. **Is there a measured problem?** A performance concern is a reason to profile first, not a reason to pick a framework on instinct. Note the asymmetry between the first two questions. The deployment-target question has a precise answer you can read from an API's availability line, while the capability question changes every year as SwiftUI grows, so revisit earlier UIKit decisions whenever the app raises its deployment target. ## Mixing the two It is rarely all or nothing, because both directions are supported: - **SwiftUI inside UIKit.** `UIHostingController` (iOS 13) presents a SwiftUI view as a view controller, which lets a UIKit app adopt SwiftUI one screen at a time; `UIHostingConfiguration` (iOS 16) puts SwiftUI content in collection and table view cells. - **UIKit inside SwiftUI.** `UIViewRepresentable` and `UIViewControllerRepresentable` wrap a UIKit view or view controller so it can sit in a SwiftUI hierarchy; their body type is `Never`, because the wrapped UIKit object supplies the content. How the representables' make, update and coordinator methods work, and how hosting controllers size themselves, is covered with SwiftUI and UIKit bridging. For this question it is enough to know the escape hatch exists, so choosing SwiftUI for a screen does not lock you out of UIKit for one stubborn component. ## A good interview answer - Lead with the model: description from state versus objects you mutate. - Default new screens to SwiftUI, and name the conditions that override the default: deployment target, a missing capability, the surrounding UIKit flow, a measured problem. - Mention the bridges in both directions as the way to make the choice per component rather than per app. - Avoid absolutes such as "SwiftUI can't do X" unless you can name the API and the release; capabilities change every year, so the senior answer is a method for deciding, not a list.

  • An app deploys back to iOS 17 and a designer wants a screen built on an iOS 18 SwiftUI API. What are your options?
    Gate the newer API with `if #available(iOS 18, *)` and provide an iOS 17 fallback, raise the deployment target if the user base allows it, or build that piece with UIKit and wrap it. Which one is right depends on how many users are still on iOS 17 and how different the fallback would look.
  • Does choosing SwiftUI for a screen mean every component on it must be SwiftUI?
    No. A UIKit view or view controller can sit inside a SwiftUI hierarchy through `UIViewRepresentable` or `UIViewControllerRepresentable`, and a SwiftUI view can be hosted in UIKit with `UIHostingController`. The choice can be made per component; the bridging lesson covers how the wrappers keep the two sides in sync.

  • SwiftUI is only for prototypes; production screens must be UIKit.
  • Every SwiftUI API works on any iOS version that supports SwiftUI.
  • Adopting SwiftUI requires rewriting the whole UIKit app at once.
  • A UIKit view can never be used inside a SwiftUI screen.
  • SwiftUI and UIKit differ only in syntax, not in how updates happen.

Assumes the iOS 27 SDK with a deployment target of iOS 17; Tab needs iOS 18 and UIHostingConfiguration iOS 16, read from their availability lines.