TechnologiesUI & App Frameworks

SwiftUI

iOSmacOStvOSwatchOSvisionOS

SwiftUI is Apple's modern, declarative UI framework that allows you to design and build user interfaces across all Apple platforms using a single, unified codebase. Instead of imperative layout engines like UIKit or AppKit, you declare what your interface should look like and how it behaves under various states. The SwiftUI runtime automatically manages the layout lifecycle, rendering changes instantly and smoothly whenever the underlying data changes.

The framework is centered around the concept of views and modifiers. A view is a lightweight, transient struct that conforms to the `View` protocol, describing a piece of user interface. You customize views by chaining modifiers — functions that wrap the view and return a modified version, such as changing fonts, applying padding, or adding gestures. State is managed using reactive property wrappers like `@State`, `@Binding`, `@StateObject`, or the modern `@Observable` macro, ensuring that UI updates are a direct function of your application state.

SwiftUI provides a comprehensive set of building blocks, from layout containers to interactive controls and navigation systems. You group items into structured containers like lists, forms, and scroll views, and manage user interactions with pickers, text fields, buttons, and sliders. Navigation is driven by modern containers like `NavigationStack` and `NavigationSplitView`. SwiftUI also integrates advanced platform features, including native accessibility rotors, focus systems, document-based app support, and immersive 3D spaces on visionOS.

Get started

Interactive SwiftUI Showcase — edit the Swift source code and preview live rendering on a virtual iPhone canvas.

Counter.swift edit · live @State · button
swift → lexer → parser → sema → uiir → canvas
Live preview tap the buttons
loading preview engine…

Key concepts

Declarative Composition

In SwiftUI, you describe your UI as a tree of views rather than a series of instructions. The body property of a View is evaluated by the system. When state changes, SwiftUI re-evaluates the body and applies a highly optimized diff to update only the modified parts of the screen.

Single Source of Truth

State flows down from a single source of truth to the views that display it. Using `@State` for local private state, `@Binding` to pass write access to child views, or environment containers to share data globally, you ensure that the UI is always in sync with your data.

Chained View Modifiers

Modifiers let you wrap and style views. Chaining is order-dependent: `.padding().background(Color.blue)` results in a padded blue box, whereas `.background(Color.blue).padding()` styles the view blue first and then adds uncolored padding around it.

Adaptive Platform Layouts

SwiftUI views automatically adapt their appearance, spacing, and control styles to the platform they run on. A `Toggle` renders as a switch on iOS, a checkbox on macOS, and a button on watchOS, while respecting dark mode and dynamic type sizing out of the box.

Presentation and Dialogs 19

Display sheets, action sheets, popovers, and alerts dynamically by binding their visibility to state properties.

Navigation 15

Coordinate transitions between screens, managing navigation paths, split views, and transitions smoothly.

Lists and Collections 16

Render collections of data as scrollable lists or grids, using custom styles and supporting swipe actions or editing.

Controls and Style Configurations 18

Interactive elements and their custom styling objects, enabling custom configurations for buttons, gauges, and labels.

Pickers and Text Fields 16

Provide selectors and input controls for user selections, menus, forms, and raw text editing.

Scrolling 14

Control scroll behaviors, visibility of indicators, target snapping, phase transitions, and custom scrolling containers.

Search and Find 7

Integrate system search bars, search suggestions, find-and-replace, and swipe-to-refresh actions.

Toolbars and Commands 9

Define system toolbars, keyboard shortcuts, keyboard press handlers, and commands for menu bar integration.

Documents 18

Types for building document-backed applications, configuring file wrappers, and opening system file dialogs.

Drag and Drop 6

Types that facilitate dragging and dropping data, matching drop proposals, and tracking active sessions.

Accessibility 8

Support voiceover, dynamic type, direct touch interaction, and custom accessibility rotors for assistive technologies.

Focus 4

Manage input focus, programmatic keyboard focus, and prioritize focus evaluation across interactive elements.

Immersive Spaces and visionOS 12

Controls for spatial computing on Apple Vision Pro, presenting immersive spaces, 3D coordinate spaces, and system breakthrough effects.

Ornaments and Glass Effects 10

Create ornaments that float near spatial windows, and apply premium glass backgrounds or plate effects.

Hover and Pointer Effects 11

Define hover states, hand-tracking highlights, and custom pointer styles for trackpads or gaze inputs.

Pencil Interactions 4

Handle Apple Pencil double-taps, squeezes, and precise hover location coordinates.

Scenes and Windows 9

Structure the window hierarchy, control window styling, handle background tasks, and manage scene restoration.

Previews and Layout Modifiers 4

Types for running live canvas previews and applying layout modifiers or animations.

Classes 2

Structures 276

Show 260 more

Enumerations 17

Show 1 more

Protocols 37

Show 21 more

Type Aliases 2

  • Ty
    TimelineViewDefaultContext
    Information passed to a timeline view's content callback.
  • Ty
    UITraitBridgedEnvironmentKey

Extends 59

ViewModifiedContentUISceneSessionActivationRequestCoordinateSpaceProtocolOptionalAnchorEnvironmentValuesGestureForEachTextImageShapeStyleTransactionPreviewTraitSubviewAttributedTextFormattingAttributedStringCustomHoverEffectPreviewCameraPreviewColorTransitionContentTransitionWiggleSymbolEffectHoverEffectContentImageRendererLayoutSubviewSectionConfigurationGeometryProxy3DNeverGroupTimelineScheduleUIViewDynamicViewContentUIViewControllerAnimationShapeZStackEmptyViewTupleContent
← UI & App Frameworks