UIKit

On this page 7

UIKit is Apple’s imperative user interface framework for iOS, iPadOS and tvOS, providing the views, view controllers, event handling and drawing infrastructure that native apps use to display content and respond to touch. In mobile app development, UIKit has been the foundation of iPhone software since 2008, and it still runs underneath many screens built with newer tools.

The framework is written in Objective-C, is fully usable from Swift, and follows an object-oriented, mutable-state model: developers create view objects, configure their properties and update them directly when data changes. That model contrasts with declarative frameworks such as SwiftUI, where the interface is described as a function of state.

How UIKit structures an iOS app

UIKit organizes an app around a hierarchy of views managed by view controllers and driven by a central run loop. The UIApplication object receives system events, the scene delegate creates one or more windows, and each UIWindow hosts a root view controller whose view tree is rendered by Core Animation.

Every visible element is a UIView subclass backed by a CALayer, which means that layout, compositing and animation are performed on the GPU through the layer tree. The main thread owns all UIKit work: updating a view from a background queue is undefined behavior and a common source of crashes and visual glitches.

The table below lists the core building blocks and the responsibility each one carries.

ComponentResponsibilityTypical subclass or example
UIApplicationOwns the event loop and app-wide stateShared singleton instance
UIScene and UIWindowSceneRepresents one instance of the app interfaceMultiple windows on iPad
UIViewControllerManages a screen, its views and lifecycleUITableViewController
UIViewDraws content and handles touches in a rectangleUILabel, UIButton, UIImageView
UIResponderBase class for the event responder chainViews, controllers, application
UIGestureRecognizerInterprets touch sequences as gesturesUITapGestureRecognizer
Core UIKit building blocks

View controller lifecycle and layout

A view controller passes through a predictable sequence of lifecycle callbacks, and correct placement of code in those callbacks determines whether a screen performs well. Expensive setup belongs in viewDidLoad, which runs once, while work tied to visibility belongs in the appear and disappear methods.

CallbackWhen it runsAppropriate work
viewDidLoadOnce, after the view is loaded into memoryCreate subviews, set constraints, bind data sources
viewWillAppearEach time before the view becomes visibleRefresh data, update navigation bar
viewDidLayoutSubviewsAfter every layout passAdjust frames that depend on final size
viewDidAppearAfter the transition completesStart animations, analytics, timers
viewWillDisappearBefore the view leaves the screenSave edits, pause playback
Main lifecycle callbacks and their intended use

Positioning is handled mainly by Auto Layout, a constraint solver based on the Cassowary algorithm that computes frames from relationships such as equal widths, fixed spacing and content priorities. Intrinsic content size, content hugging and compression resistance priorities decide which view stretches or truncates when space runs short.

Developers can also set frames manually or use UIStackView, which generates constraints for rows and columns automatically. Interfaces may be built in code, in Interface Builder storyboards inside Xcode, or in a combination of both, and many teams favor code for easier code review and fewer merge conflicts.

UIKit compared with SwiftUI and cross-platform toolkits

UIKit differs from its alternatives mainly in programming model, control and platform reach. SwiftUI, introduced in 2019, describes interfaces declaratively and diffs state changes, while Flutter and React Native render or bridge interfaces from a shared codebase for both iOS and Android.

TechnologyModelPlatformsMain strength
UIKitImperative, object-orientediOS, iPadOS, tvOS, visionOSFine-grained control and maturity
SwiftUIDeclarative, state-drivenAll Apple platformsLess code and live previews
FlutterDeclarative, own rendering engineiOS, Android, web, desktopPixel-identical cross-platform UI
React NativeDeclarative, native componentsiOS, AndroidJavaScript skills and code sharing
UIKit versus related interface technologies

The two Apple frameworks are interoperable rather than exclusive. UIHostingController embeds SwiftUI views inside a UIKit hierarchy, and UIViewRepresentable wraps a UIKit view for use in SwiftUI. Much of SwiftUI on iOS is still rendered through UIKit components internally, so UIKit knowledge remains useful even in SwiftUI-first projects.

When to choose UIKit in practice

UIKit is the better choice when a project needs precise control over layout, scrolling or text, or must support older iOS versions. SwiftUI is usually faster for new, standard screens, so many teams adopt a hybrid architecture and decide per feature.

SituationRecommended approachReason
Large existing Objective-C or Swift codebaseContinue in UIKit, add SwiftUI graduallyRewrites carry high risk and cost
Complex lists with thousands of cellsUICollectionView with diffable data sourceProven cell reuse and prefetching
Custom text editing or rich textUITextView and TextKit 2Deeper access to text layout
New app targeting recent iOS onlySwiftUI with UIKit for gapsFaster development of standard screens
Shared iOS and Android productCross-platform toolkit or two native appsUIKit does not run on Android
Decision guide for UIKit adoption

Modern UIKit includes compositional layouts, diffable data sources and the configuration-based cell and button APIs, which remove much of the boilerplate that earlier versions required. Apple continues to add UIKit features each year, so the framework is maintained, not deprecated.

Common UIKit mistakes and limitations

Most UIKit defects come from threading errors, retain cycles and oversized view controllers. The imperative model gives developers full responsibility for keeping the interface synchronized with data, which declarative frameworks partly automate.

  • Massive view controller: networking, formatting and navigation pile into one class; patterns such as MVVM or coordinators split responsibilities.
  • Background-thread UI updates: results from URLSession arrive off the main thread and must be dispatched back before touching views.
  • Strong reference cycles: closures that capture self strongly keep controllers alive; [weak self] breaks the cycle.
  • Ambiguous constraints: missing or conflicting Auto Layout rules produce console warnings and unpredictable frames.
  • State drift: forgetting to update one label after a data change leaves the screen inconsistent, a problem SwiftUI avoids by design.

UIKit is also limited to Apple platforms. On macOS it runs only through Mac Catalyst, which adapts iPad apps rather than offering the native AppKit experience.

In simple terms

UIKit is the toolbox Apple gives developers for building the screens of iPhone and iPad apps. It contains ready-made parts such as buttons, text fields, lists and navigation bars, plus the machinery that notices when a finger touches the glass.

Working with UIKit is a bit like arranging furniture by hand. The developer places each piece, and when something changes, the developer moves that piece personally. Newer tools such as SwiftUI work more like a floor plan that rearranges the room automatically. UIKit asks for more manual work but offers very precise control.

A practical example

A banking app with about 400,000 lines of UIKit code needs a new spending dashboard. Rewriting the whole app in SwiftUI would take more than a year, so the mobile team keeps the existing navigation, login and transaction screens in UIKit and builds only the new dashboard as a SwiftUI view.

The team embeds the dashboard with UIHostingController inside the existing tab bar. The transaction history, which shows up to 10,000 rows per account, stays a UICollectionView with a diffable data source because its cell reuse keeps scrolling at 120 frames per second on ProMotion displays. The result is a feature delivered in eight weeks without destabilizing the mature UIKit code that customers rely on every day.