Fact-checked by Grok 2 weeks ago

SwiftUI

SwiftUI is a declarative user interface (UI) framework developed by Apple for creating native applications across all its platforms, including iOS, iPadOS, macOS, tvOS, watchOS, and visionOS. Introduced on June 3, 2019, at the Worldwide Developers Conference (WWDC), it allows developers to describe the desired appearance and behavior of user interfaces using Swift code, enabling faster development of dynamic, responsive apps with less boilerplate compared to imperative frameworks. At its core, SwiftUI provides a suite of views, controls, and layout structures that serve as the building blocks for app interfaces, such as stacks for arranging elements, lists for displaying data, and modifiers for customizing appearance and interactivity. It supports event handling for user inputs like taps, gestures, and keyboard events, while promoting composability to combine simple components into complex designs. The framework's declarative approach—where developers specify what the UI should be rather than how to update it—facilitates automatic state management and real-time previews during development in Xcode, reducing errors and accelerating iteration. SwiftUI integrates seamlessly with Apple's ecosystem, allowing hybrid use with older frameworks like UIKit for iOS/iPadOS, AppKit for macOS, and WatchKit for watchOS to leverage platform-specific features without full rewrites. It also emphasizes accessibility, internationalization, and adaptive layouts that automatically adjust to different device sizes, orientations, and interaction models, such as spatial computing on visionOS. Since its launch, SwiftUI has evolved through annual WWDC updates, incorporating enhancements like improved animation controls, data flow tools (e.g., @State and @Observable), Liquid Glass design, and 3D integration with RealityKit, making it the preferred framework for new Apple app development.

Introduction

Overview

SwiftUI is Apple's declarative user interface framework designed for building native applications across its ecosystem using the Swift programming language. It enables developers to describe what the user interface should look like and how it should behave, rather than specifying step-by-step instructions, allowing for more intuitive and maintainable code. This approach leverages Swift's modern syntax and type safety to create responsive, adaptive interfaces that automatically update in response to data changes. The framework supports development for multiple Apple platforms, including iOS, iPadOS, macOS, tvOS, watchOS, and visionOS, facilitating code reuse and consistent experiences across devices. Key benefits include the ability to share UI code across platforms with minimal adjustments, thanks to adaptive views and controls that conform to platform-specific guidelines. As of WWDC 2025, SwiftUI introduced features like the Liquid Glass design for enhanced visual effects and improved performance tools. Additionally, SwiftUI integrates seamlessly with Swift's strong type system, reducing runtime errors and enhancing developer productivity through compile-time checks. SwiftUI offers interoperability with established frameworks such as UIKit for iOS and iPadOS, AppKit for macOS, and WatchKit for watchOS, allowing developers to incorporate legacy components or gradually migrate existing apps. A standout feature is its real-time preview capability in Xcode and Swift Playgrounds, where changes to the code instantly reflect in a live canvas, accelerating the design and iteration process without requiring full app compilation or device testing. This live previewing supports rapid prototyping and debugging, making it easier to visualize UI behavior on various device sizes and orientations.

Key Principles

SwiftUI is fundamentally built on declarative programming, where developers describe the desired user interface and its behavior based on the current state, rather than specifying step-by-step instructions for updating the UI as in imperative paradigms. This approach allows the framework to automatically handle rendering and updates, focusing developer effort on the "what" of the interface rather than the "how" of its manipulation. Central to SwiftUI's design is reactivity, which ensures that the user interface automatically reflects changes in underlying data. This is achieved through Swift's property wrappers, such as @State for managing local, mutable state within a view as the single source of truth, and @Binding for creating two-way connections that propagate changes across views. When data updates occur, SwiftUI recomputes and redraws only the affected parts of the view hierarchy, enabling efficient, responsive UIs without manual intervention. Composability forms another core principle, allowing complex interfaces to be constructed by combining simple, reusable view components into hierarchies. Views in SwiftUI conform to the View protocol and can be nested using layout primitives like stacks, enabling modular and scalable UI design across platforms. This composition promotes code reuse and maintainability, as smaller views can be assembled into larger structures without tight coupling. SwiftUI's tight integration with Swift emphasizes type safety, leveraging the language's strong static typing to catch UI-related errors at compile time. By defining views as lightweight structs that adhere to Swift's type system, the framework ensures that incompatible types or invalid configurations are detected early, reducing runtime issues and enhancing reliability. This compile-time checking extends to UI code, making it as robust as general Swift development. Supporting iterative development, SwiftUI incorporates live previews in Xcode, which provide instant visual feedback of UI changes without requiring full app builds or device runs. These previews render views in real-time as code is edited, allowing developers to experiment and refine designs rapidly. This feature streamlines the development workflow, particularly for prototyping and debugging visual elements.

History and Development

Announcement and Initial Release

SwiftUI was announced on June 3, 2019, during Apple's Worldwide Developers Conference (WWDC) in San Jose, California. The framework was presented as a revolutionary tool for building user interfaces, integrated into Xcode 11 to enable developers to create apps across all Apple platforms with a unified approach. The development of SwiftUI stemmed from the need to streamline user interface creation on Apple platforms, tackling issues in existing frameworks like UIKit for iOS and AppKit for macOS, such as verbose imperative code, manual layout management with constraints, and inconsistencies between platforms that required separate implementations. By adopting a declarative syntax, SwiftUI allowed developers to describe the desired UI state, with the system automatically handling updates, animations, and adaptations for features like Dark Mode and accessibility. This shift aimed to reduce development time and code volume, fostering better collaboration between designers and engineers through real-time previews in Xcode. SwiftUI's initial public release occurred in September 2019, with the launches of iOS 13 and watchOS 6 on September 19, 2019, iPadOS 13 and tvOS 13 on September 24, 2019, followed by macOS Catalina (version 10.15) on October 7, 2019. It was made available via Xcode 11, which provided tools like SwiftUI previews exclusively on macOS Catalina and later. However, the framework's early version had limited capabilities, including incomplete parity with AppKit for macOS-specific features and a lack of some advanced controls available in UIKit. Initial reception highlighted praise for SwiftUI's declarative syntax, which promised leaner code and faster prototyping compared to traditional methods. Developers appreciated its potential to unify UI development across platforms, reducing the pain points of maintaining separate codebases. That said, early adopters encountered challenges from beta-stage bugs, such as inconsistent rendering and preview issues in Xcode, alongside sparse documentation that made exploration difficult during the initial betas. These factors positioned SwiftUI as a promising but maturing framework at launch, best suited for new projects targeting iOS 13 and equivalent OS versions.

Major Updates and Releases

SwiftUI has evolved significantly since its initial release, with annual updates at Apple's Worldwide Developers Conference (WWDC) introducing enhancements that expand its capabilities across Apple platforms. These updates focus on improving developer productivity, performance, and integration with new hardware and software features, while gradually reducing reliance on underlying UIKit components for more native declarative implementations. At WWDC 2020, coinciding with iOS 14 and macOS Big Sur, SwiftUI gained support for widgets through integration with WidgetKit, allowing developers to create customizable home screen widgets directly in SwiftUI. The framework also introduced a native Map view powered by MapKit, enabling interactive maps without bridging to UIKit, and optimized list performance with lazy loading mechanisms to handle large datasets more efficiently. These additions marked a step toward broader adoption by addressing common UI needs like location-based content and glanceable information displays. The WWDC 2021 update for iOS 15 and SwiftUI 3 brought the Canvas view for custom vector drawing and graphics rendering, facilitating complex visual effects without external libraries. AsyncImage was added to streamline remote image loading with built-in caching and placeholder support, reducing boilerplate code for network-dependent UIs. Enhancements to the focus system improved keyboard navigation and accessibility, particularly for tvOS and macOS apps, by providing finer control over focus movement and styling. These features emphasized SwiftUI's growing maturity in handling asynchronous operations and custom visuals. In 2022, with iOS 16, SwiftUI integrated the new Swift Charts framework, allowing declarative creation of interactive data visualizations like bar charts and line graphs directly within views. Navigation was overhauled with NavigationStack and NavigationSplitView for more customizable and programmatic control, supporting deep linking and state preservation. Multi-window support on iPadOS enabled seamless handling of multiple app instances, aligning SwiftUI with macOS multitasking paradigms. This release highlighted SwiftUI's expansion into data-driven and multi-surface experiences. WWDC 2023 introduced native support for visionOS 1 alongside iOS 17, enabling SwiftUI apps to render in spatial computing environments with volumetric layouts and immersive spaces. Accessibility APIs were enhanced with better VoiceOver integration, dynamic type scaling, and reduced motion options, making it easier to build inclusive interfaces compliant with WCAG standards. These updates positioned SwiftUI as a unified framework for emerging AR/VR platforms while prioritizing user inclusivity. For iOS 18 at WWDC 2024, SwiftUI added window pushing APIs for smoother transitions between scenes on iPadOS and macOS, along with observation tools for text selection in TextField and TextEditor views to enable real-time interactions like custom menus. New tab and document group APIs facilitated advanced multitasking on iPad, including scene-based management for external displays. These refinements improved SwiftUI's handling of complex, multi-window workflows. The most recent WWDC 2025 update for iOS 19 incorporated the Liquid Glass design system, a new material-inspired aesthetic with translucent, adaptive elements that respond to environmental lighting and depth. Interactive 3D charts extended Swift Charts with rotatable, gesture-driven visualizations for enhanced data exploration. Web API integrations allowed direct embedding of web content with native controls, while optimizations for lists and scrolling reduced lag in long-view hierarchies by up to 40% in benchmarks. Release notes from this cycle also noted deprecations for several UIKit bridging APIs, signaling a full transition to native SwiftUI implementations and encouraging migration from older wrappers.

Core Concepts

Declarative Programming

SwiftUI employs a declarative programming paradigm, in which developers describe the desired state and behavior of the user interface, allowing the framework to automatically manage the rendering and updates. This contrasts with imperative approaches in frameworks like UIKit, where developers must explicitly instruct the system on how to construct and modify views in response to data changes, such as by calling methods to add, remove, or update subviews manually. In SwiftUI, the focus shifts to specifying what the UI should look like given the current data, enabling more concise code and automatic handling of transitions between states. At the core of SwiftUI's declarative model is the View protocol, which requires conforming types to implement a computed body property that returns a hierarchy of views representing the UI description. This property is evaluated on-demand based on the current state and environment, generating a lightweight, value-based representation of the interface rather than a heavy object graph. When state changes occur, SwiftUI recomputes the body of affected views, ensuring the UI reflects the latest data without requiring developers to manage the update process imperatively. SwiftUI's runtime employs an internal diffing mechanism to compare the new view description against the previous one, identifying and updating only the changed portions of the view tree for efficient rendering. This dependency-tracking system minimizes unnecessary recomputations by monitoring which parts of the UI depend on specific data sources, such as observable objects, and triggers targeted updates accordingly. As a result, the framework handles complex animations and transitions seamlessly while preserving performance. The declarative paradigm in SwiftUI offers several advantages, including reduced boilerplate code compared to imperative alternatives, as developers can express UI intent succinctly without detailing every update step. It also enhances separation of concerns by isolating UI descriptions from underlying logic and data management, making applications easier to maintain and reason about. Additionally, the approach facilitates rapid iteration through real-time previews and automatic state-driven updates, streamlining development workflows. However, SwiftUI's declarative nature provides less granular control over low-level rendering and customization than imperative frameworks like UIKit, where developers can directly manipulate view layers and drawing contexts. For scenarios requiring such fine-tuned behaviors, integration with UIKit via hosting controllers is often necessary to leverage its imperative capabilities.

Views and View Hierarchy

In SwiftUI, all user interface elements conform to the View protocol, which serves as the foundational building block for declarative UI construction. Custom views are typically implemented as lightweight value types, such as structs, that adopt this protocol and define their content through a required computed property named body. This design promotes immutability and efficiency, allowing views to be composed and recomputed without side effects during runtime updates. The view hierarchy in SwiftUI forms a tree-like structure, where parent views encapsulate child views to define the overall layout and relationships within the user interface. This hierarchy is dynamically computed via the body property of each view, which returns a single some View—often a composition of other views, containers like VStack or HStack, and modifiers. When state changes occur, SwiftUI re-evaluates the relevant portions of the hierarchy to update the rendered output, ensuring a responsive and performant interface without manual invalidation. View modifiers are chainable functions provided by the View protocol that transform an existing view into a new one, applying stylistic or structural changes without mutating the original. For instance, the .padding() modifier adds specified spacing around a view's edges, while .background() overlays a shape or color behind the view, both returning an updated view instance for further composition. These modifiers enable flexible, readable declarations, such as Text("Hello").padding().background(Color.blue), fostering reusable and modular UI code. SwiftUI manages view identity and equality to optimize rendering and diffing of hierarchies, particularly during updates to dynamic content like lists. The Identifiable protocol is commonly adopted by data models to provide a stable, unique identifier (id), allowing SwiftUI to track and animate changes efficiently without rebuilding unaffected views. For explicit view-level identity, the .id() modifier assigns a custom identifier to a view, preventing unnecessary recreations and preserving state across recomputations. Previews facilitate rapid iteration on view hierarchies directly within Xcode using the #Preview macro, introduced in Xcode 15, which generates interactive renderings of specified views in the canvas alongside source code. Developers attach this macro to a view struct, providing a closure that returns the view instance—optionally with custom traits like device simulators or accessibility settings—to visualize and test compositions without running the full app. This tool integrates seamlessly with the declarative nature of SwiftUI, updating previews in real-time as code changes.

State Management

In SwiftUI, state management refers to the mechanisms that enable views to respond automatically to changes in data, ensuring the user interface remains synchronized with the underlying model. This is achieved through a declarative approach where views declare their dependencies on state, and the framework handles updates efficiently. SwiftUI uses property wrappers to manage different types of state, from local values to shared references and external objects, forming the foundation for reactive UI updates. The @State property wrapper is designed for storing mutable, view-specific data that does not need to be shared beyond the current view. It creates a local source of truth for simple value types, such as booleans or strings, and SwiftUI automatically preserves and updates the value across view redraws without requiring manual intervention. For example, a toggle switch might use @State private var isEnabled = false to track its state internally. In contrast, @Binding provides a two-way reference to an existing @State variable, allowing child views to read and modify the parent's state without duplicating storage. This is typically accessed via the projected value of @State, such as $isEnabled, enabling seamless data flow in view hierarchies. For more complex, external data models, @ObservedObject wraps instances conforming to the ObservableObject protocol, allowing views to observe and react to changes in shared objects. The ObservableObject protocol, part of the Combine framework, requires marking mutable properties with @Published to emit change notifications, triggering view invalidation only when relevant properties update. A common pattern involves creating the object with @StateObject in a parent view and passing it down via @ObservedObject to subviews, ensuring ownership and efficient observation. For instance, a data model like class UserSettings: ObservableObject { @Published var theme: Theme = .light } can drive theme switches across multiple views. Introduced in iOS 17, the Observable macro simplifies observation by eliminating the need for the ObservableObject protocol and @Published wrappers. Classes annotated with @Observable automatically track changes to their properties, with SwiftUI forming fine-grained dependencies on only those accessed by a view's body, leading to more performant updates. Properties can be excluded from observation using @ObservationIgnored if they do not affect the UI. This approach replaces @StateObject and @ObservedObject with direct @State usage for observable classes, reducing boilerplate and supporting better tracking of optionals and collections. Migration involves incrementally applying the macro to models while maintaining compatibility with older APIs. To propagate state down deep view hierarchies without prop passing, SwiftUI provides the environment system, including @EnvironmentObject. This property wrapper accesses an ObservableObject instance injected into the environment via the environmentObject(_:) modifier on an ancestor view, making it available to all descendants. Changes to the object invalidate dependent views automatically, ideal for app-wide settings like user sessions. For non-observable values, @Environment serves a similar role for read-only propagation. Best practices for state management emphasize encapsulation and minimalism to avoid unnecessary view updates. Declare @State variables as private and limit them to transient UI data, storing persistent or shared data in dedicated models instead. Use a single source of truth by placing state in the lowest common ancestor view, preventing duplication and conflicts. Avoid circular dependencies, such as mutual bindings between parent and child that could cause infinite loops; instead, favor unidirectional flow with @ObservedObject. Overusing @State for complex objects can lead to performance issues, so prefer observable models for anything beyond simple values. Animate state changes explicitly with withAnimation to enhance user experience. SwiftUI integrates with the Combine framework at a high level through the ObservableObject protocol and @Published properties, enabling reactive streams for asynchronous data handling. This allows state to respond to publisher emissions, such as network updates, while keeping the core observation declarative and view-focused.

Components and Features

Basic Views and Controls

SwiftUI provides a suite of built-in views and controls that form the foundation for constructing user interfaces across Apple platforms. These primitives enable developers to display content, handle user input, and present structured data without requiring manual layout or event handling code. By composing these elements declaratively, apps can achieve native appearance and behavior tailored to iOS, macOS, watchOS, and tvOS.

Text and Label

The Text view in SwiftUI is designed for displaying static or dynamic strings in an app's interface, automatically selecting a body font suitable for the platform to ensure readability. Developers initialize it with a string literal or interpolated value, such as Text("Hello, World!"), and can apply modifiers for customization, including font size, weight, color, and alignment. For instance, .font(.title) increases the text size, while .foregroundColor(.blue) changes its hue, allowing precise styling without subclassing. This view supports multiline content and adapts to localization through string catalogs. In contrast, the Label view combines text with an icon, typically from the SF Symbols library, to create accessible and visually informative elements like buttons or list items. It is initialized with a title string and image name, as in Label("Settings", systemImage: "gear"), which pairs the text with a symbolic icon and ensures proper VoiceOver descriptions for accessibility. Labels support various styles via labelStyle(_:) and can use any view as content, promoting consistent iconography in interfaces.

Image and AsyncImage

The Image view renders images from asset catalogs, SF Symbols, or system resources, supporting resizable and scalable content for diverse screen sizes. It can be initialized from a named asset, like Image("profilePhoto"), and modified with .resizable() to fit containers or .clipShape(Circle()) for custom shapes. This view handles color inversion for dark mode and provides rendering modes such as .original or .template for tinting. Introduced in iOS 15, iPadOS 15, macOS 12, and watchOS 8, AsyncImage extends this capability to load remote images asynchronously, preventing UI blocking during network requests. It uses a URL initializer, such as AsyncImage(url: URL(string: "https://example.com/image.jpg")) { image in image.resizable() } placeholder: { ProgressView() }, where the content closure renders the loaded image and a placeholder manages loading states like empty, success, or failure via AsyncImagePhase. This integrates seamlessly with Swift's concurrency model for efficient remote content display.

Button, Toggle, Slider

The Button view serves as a primary interactive control, executing a specified action—such as a closure or method—upon user tap or click, with support for platform-specific interactions like selection on tvOS. Its label accepts any view, enabling rich content like text, images, or labels, as in Button("Tap Me") { print("Tapped") }; roles like .destructive alter appearance for warnings, and styles via buttonStyle(_:) (e.g., .borderedProminent) ensure adaptive theming. Buttons integrate with containers like lists for contextual actions. For binary state management, the Toggle view binds to a Boolean property to switch between on and off states, displaying as a switch on iOS or checkbox on macOS. Initialized with Toggle("Enable Feature", isOn: $enabled), it updates the binding on interaction and accepts custom labels for clarity; styles like .switch or .button adapt to context, with automatic accessibility support for state announcements. The Slider view allows selection of continuous values within a range, featuring a draggable thumb along a track from minimum to maximum bounds. It binds to a numeric value, such as Slider(value: $volume, in: 0...1), and supports step increments for discrete adjustments; optional labels and editing callbacks via onEditingChanged provide feedback during drags. On iOS, it visually indicates progress, while macOS versions include tick marks for precision.

List and Form

List presents scrollable rows of data in a single column, ideal for collections with optional selection, deletion, or editing modes. It accepts views for rows or uses ForEach for dynamic content, like List { ForEach(items) { item in Text(item.name) } }, automatically handling scrolling, separators, and pull-to-refresh; sections group related items, and .onDelete enables swipe-to-delete gestures. This view adapts to platform idioms, such as plain lists on iOS or outline views on macOS. Form structures grouped inputs with platform-specific styling, such as rounded sections on iOS, suitable for settings or data entry. It wraps controls like toggles or text fields, as in Form { Toggle("Notifications", isOn: $notifications) TextField("Name", text: $name) }, applying consistent padding and backgrounds; unlike List, it emphasizes form-like hierarchy over long scrolling lists, with built-in validation cues.

Progress Views and Alerts

ProgressView indicates task completion progress, supporting determinate modes with a value (e.g., ProgressView(value: 0.5) for 50% completion) or indeterminate spinning for unknown durations. It displays as a bar on iOS or circular on macOS, with customizable labels and styles like .circular; integration with timers allows animated updates for operations like file downloads. Alert presents modal notifications requiring user response, triggered by state changes via bindings. Configured with title, message, and actions, such as .alert("Error", isPresented: $showAlert) { Button("OK") {} } message: { Text("Something went wrong") }, it overlays the interface with platform-appropriate sheets or dialogs, supporting destructive actions and text fields for input. Use it for confirmations or errors rather than passive info.

Recent Additions

In iOS 18, iPadOS 18, macOS 15, tvOS 18, and watchOS 11 (announced at WWDC 2024), SwiftUI introduced mesh gradients for advanced visual effects, allowing developers to create complex, flowing color transitions with MeshGradient. Enhanced TabView supports custom tab bars and behaviors, improving navigation in tab-based apps. ScrollView received performance optimizations for smoother scrolling and better integration with large datasets. Further updates in iOS 19, iPadOS 19, macOS 16, tvOS 19, and watchOS 12 (announced at WWDC 2025) added the Liquid Glass material for dynamic, refractive UI elements, enhancing visual depth. Interactive 3D charts extend Swift Charts with RealityKit integration for rotatable, spatial data visualizations. Advanced rich text editing capabilities allow inline formatting and custom controls within TextEditor. New web API integrations enable seamless in-app web content handling. These features emphasize performance improvements, such as better large list rendering and scrolling scheduling. Earlier additions, such as the Map view available since iOS 14, iPadOS 14, macOS 11, and watchOS 7, and Swift Charts introduced in iOS 16, iPadOS 16, macOS 13, tvOS 16, and watchOS 9, provide foundational support for location-based content and data visualization.

Layout and Navigation

SwiftUI provides a declarative approach to arranging views through container views that handle layout, alignment, and spacing, enabling developers to compose complex interfaces without manual frame calculations. Fundamental to this system are stack views, which organize child views in linear or overlaid arrangements. These containers adapt to the available space and device orientation, ensuring responsive designs across Apple platforms. Stacks form the building blocks for linear layouts. VStack arranges views vertically in a top-to-bottom sequence, while HStack positions them horizontally from left to right. Both support parameters for alignment (such as .center or .leading) and spacing (e.g., fixed values or adaptive gaps), allowing precise control over the arrangement without overlapping. For overlaying views, ZStack stacks them along the z-axis, with the last view in the declaration appearing on top; it also uses alignment and spacing to position elements relative to a shared origin. These stacks render all subviews immediately, making them suitable for small, fixed sets of content. For displaying collections in adaptive grid layouts, SwiftUI introduces lazy grids starting from iOS 14. LazyVGrid creates a vertically scrolling grid where views load only when entering the visible area, improving performance for large datasets; it uses column specifications (e.g., fixed widths or flexible spacing) to define the layout. Similarly, LazyHGrid enables horizontal scrolling with row-based arrangements. These grids integrate seamlessly with data sources like ForEach, allowing dynamic content population while maintaining efficient rendering. Navigation in SwiftUI manages transitions between views, supporting hierarchical or programmatic flows. The modern NavigationStack, introduced in iOS 16, replaces the legacy NavigationView and uses a path binding for stack-based navigation, enabling features like deep linking and state restoration. Developers add navigation via NavigationLink, which pushes destinations onto the stack, or programmatically through path modifications. NavigationView remains available for backward compatibility but lacks the enhanced programmatic control and performance of NavigationStack. Toolbar integration, such as .navigationTitle and .toolbar, provides consistent header elements across navigated views. Modal presentations overlay content for focused interactions, distinct from navigation stacks. The .sheet modifier presents a dismissible view that adapts to device size classes, typically as a bottom sheet on iPhone or centered on iPad. For immersive experiences, .fullScreenCover displays a view covering the entire screen, ideal for onboarding or alerts, with optional dismiss handlers. Both use bindings (e.g., @State for Boolean triggers or identifiable items) to control presentation and integrate with state management. Scrollable content extends layouts beyond the screen bounds. ScrollView wraps any view hierarchy to enable scrolling along specified axes (vertical, horizontal, or both), with options for disabling bounce or indicators. For list-based scrolling, List provides a performant, row-oriented container that recycles views and supports selection, editing, and sections; it inherently scrolls and pairs well with navigation for detail views. ScrollView can embed stacks or grids for custom scrollable areas, while List optimizes for data-driven rows. On iPadOS, SwiftUI enhances layout for multitasking with split views and multi-window support, introduced in iPadOS 16. NavigationSplitView divides the interface into sidebar, detail, and optional supplementary columns, adapting to compact or regular environments; users select sidebar items to update the detail pane, supporting columnar navigation without modals. Multi-window navigation allows apps to manage state across scenes, using @Environment(\.scenePhase) to respond to window events and NavigationStack for consistent paths in each window, facilitating productivity workflows on larger screens.

Animations and Gestures

SwiftUI provides a declarative approach to incorporating animations and user gestures into user interfaces, allowing developers to define smooth transitions and interactive behaviors that respond to state changes and user input without managing low-level timing or event handling. Animations in SwiftUI are triggered automatically by view updates, while gestures enable direct manipulation of views through touches, drags, and other inputs. This integration ensures that motion feels natural and responsive across Apple platforms. Implicit animations occur automatically when a view's state changes, such as updating properties like opacity or position, and can be customized using the .animation() modifier to apply effects like fade or slide transitions. For instance, applying .animation(.easeInOut(duration: 0.5)) to a view will smoothly animate any bound state changes within that view hierarchy, with the animation curve determining the acceleration and deceleration of the motion. This modifier supports various predefined animation types, including linear, ease-in, and ease-out, allowing developers to match the visual feedback to the app's design language without explicit code for each transition. Explicit animations offer finer control by wrapping state updates in a withAnimation block, which scopes the animation to specific code execution and prevents unintended triggers across the view tree. Within this block, developers can specify custom parameters, such as duration and animation curves, to create coordinated effects; for example, withAnimation(.spring(response: 0.6, dampingFraction: 0.8)) { isVisible.toggle() } animates a toggle with a bouncy spring effect. This approach is particularly useful for sequencing multiple changes or applying animations conditionally based on user actions. Easing functions, like cubic or spring-based curves, further refine the feel by simulating natural physics, enhancing perceived smoothness. Gestures in SwiftUI are attached to views using modifiers like .gesture(), supporting built-in recognizers for common interactions such as taps, drags, and long presses. The TapGesture detects single or multiple taps with configurable counts, while DragGesture tracks translation, velocity, and state changes during finger movement, enabling features like panning or resizing. LongPressGesture requires a minimum duration before recognition, useful for contextual menus, and gestures can be combined using SimultaneousGesture for concurrent handling (e.g., drag while tapped) or ExclusiveGesture to prioritize one over another. These recognizers provide value objects with details like location and predicted end points, allowing real-time updates to view properties. Custom gestures extend built-in ones by composing multiple recognizers into sequences or groups, using SequenceGesture to require ordered execution (e.g., long press followed by drag) or AnyGesture for type-erased wrappers. Developers attach these to views, binding gesture outcomes to state variables for dynamic responses, such as animating a view's offset based on drag distance. This composition supports complex interactions like pinch-to-zoom without relying on platform-specific APIs. Introduced in iOS 14 and later, physics-based animations add realism through spring and momentum effects, where Animation.spring() simulates oscillatory damping for button presses or reveals, controlled by response time and damping fraction. Momentum animations extend drags with inertia, predicting continuation based on velocity, ideal for scrollable lists or interactive maps. These leverage Core Animation under the hood but remain declarative in SwiftUI. Accessibility is integrated via the @Environment(\.accessibilityDisabled) property, which respects user preferences for reduced motion by disabling or simplifying animations and gestures when enabled in system settings. This ensures inclusive experiences, automatically applying static alternatives like instant transitions, while allowing developers to query the environment for conditional behaviors.

Data Binding and Combine

SwiftUI leverages the Combine framework to enable reactive data binding, allowing views to automatically update in response to asynchronous events and data changes. Combine provides a declarative API for processing values over time, including publishers that emit data, subscribers that receive it, and operators that transform or filter streams. In SwiftUI, this integration facilitates seamless handling of dynamic content, such as network responses or user inputs, by connecting publishers directly to view properties. The @Published property wrapper and ObservableObject protocol form the core of Combine's data binding in SwiftUI. An ObservableObject is a type that conforms to the protocol, synthesizing an objectWillChange publisher that emits before any @Published properties change, triggering view updates. The @Published wrapper marks properties in an ObservableObject to automatically publish changes via Combine, ensuring that SwiftUI re-renders dependent views efficiently. For instance, a view model class might declare a @Published var items: [String] = [], and any assignment to items will propagate updates to observing views without manual intervention. Integrating Combine with URLSession allows SwiftUI views to fetch and bind remote data reactively. The URLSession.DataTaskPublisher creates a publisher from a URL request, emitting (data: Data, response: URLResponse) upon completion. Developers can chain operators like decode(type:decoder:) to parse JSON into model types, then assign the result to a @Published property for automatic UI binding. A typical pattern involves subscribing to this publisher in an ObservableObject's initializer or method, using sink to update state: for example, URLSession.shared.dataTaskPublisher(for: url).map(\.data).decode(type: [Item].self, decoder: JSONDecoder()).sink(receiveValue: { self.items = &#36;0 }).store(in: &cancellables). Error handling in Combine-enhanced SwiftUI bindings uses operators like catch(_:) and the Result type to manage failures gracefully. The URLSession.DataTaskPublisher can fail with URLError, which propagates downstream unless intercepted. To bind errors to UI elements, developers map failures to a @Published error state using mapError or catch, then display them via alerts: for example, presenting an Alert bound to a @State var error: Error?. The Result type encapsulates success or failure values, allowing publishers to emit Result<T, Error> for conditional UI rendering, such as showing a loading spinner on .loading or an error message on .failure. Advanced patterns in SwiftUI's Combine usage include sinking streams to update observable state and transforming data with operators like map and compactMap. Sinking a publisher to a @Published property via assign(to:) directly binds emissions to the property, ideal for simple updates. For complex transformations, map applies synchronous closures to reshape values—e.g., extracting a subset of data—while compactMap filters nil results from optional mappings, ensuring clean streams before assignment. These operators enable pipelines like filtering network data before UI binding, maintaining declarative reactivity without imperative loops. While Combine remains integral for complex asynchronous flows in SwiftUI, Apple introduced the Observation framework in iOS 17, iPadOS 17, macOS 14, tvOS 17, and watchOS 10 as a lighter alternative to @ObservableObject and @Published for simpler state management. The @Observable macro replaces these Combine-based wrappers, offering more efficient, type-safe observation without publishers, though Combine persists for advanced scenarios like custom publishers or third-party integrations. Subsequent updates in iOS 18 and iOS 19 enhanced Observation with improved async support, better environment handling, and simplified data flow management, reducing boilerplate further for modern SwiftUI apps.

Platform Integration

Cross-Platform Support

SwiftUI enables developers to create applications that run across multiple Apple platforms, including iOS, iPadOS, macOS, tvOS, watchOS, and visionOS, by leveraging a unified codebase within a single multiplatform target in Xcode 14 and later. This approach shares project settings and core code, such as the app's life cycle defined by a single App structure, while allowing platform-specific customizations. For instance, developers can use conditional compilation directives like #if os(iOS) or #if os(macOS) to include or exclude code tailored to specific operating systems, ensuring compatibility without duplicating entire projects. Additionally, #if canImport(framework) checks help manage availability of platform-exclusive frameworks, such as ARKit on iOS and visionOS. To align with platform-specific idioms, SwiftUI applications must adapt user interfaces for varying input methods, such as touch gestures on iOS and iPadOS versus mouse, trackpad, and keyboard interactions on macOS. SwiftUI automatically converts many iPadOS gestures to macOS equivalents in multiplatform apps, but developers often use conditional code to refine layouts, like adding menu bar extras on macOS or optimizing for resizable windows. On touch-based platforms, emphasis is placed on intuitive swipe and pinch gestures, while macOS prioritizes precise pointer interactions and keyboard shortcuts to enhance productivity. SwiftUI integrates seamlessly with WidgetKit to build widgets that appear on the iOS and iPadOS Home Screen as well as in the macOS Notification Center, starting from iOS 14 and macOS Big Sur. These widgets use SwiftUI views to display glanceable content, with shared timelines and providers enabling consistent updates across platforms via push notifications or background refreshes. For example, a single SwiftUI view can render dynamic data like weather or notifications in both contexts, adapting size and interactivity as needed. On tvOS, SwiftUI supports focus-based navigation using the Apple TV remote, with limited gesture recognition compared to touch platforms; standard interactions rely on select, swipe for menus, and directional controls rather than multi-touch drags or pinches. Custom buttons and views must account for focus styles to ensure accessibility via remote input. Similarly, watchOS apps in SwiftUI face constraints from the small screen and Digital Crown input, requiring larger touch targets—at least 42 points in diameter—to accommodate finger precision, and restricting complex gestures to simple taps and rotations. Feature availability in SwiftUI varies by platform and release, promoting parity where possible but including exclusives like spatial layouts and 3D modifiers on visionOS for immersive experiences. Core views, such as Text and Button, render consistently across platforms with automatic adaptations, but advanced features like volumetric windows are visionOS-specific. Testing multiplatform SwiftUI apps involves Xcode simulators for each OS, allowing developers to verify behavior without physical devices, combined with conditional compilation to isolate platform code during builds. This setup enables targeted debugging, such as simulating tvOS remote gestures or watchOS crown rotations, ensuring reliable performance across environments.

Interoperability with UIKit and AppKit

SwiftUI provides seamless interoperability with UIKit for iOS and iPadOS, and AppKit for macOS, enabling developers to integrate existing imperative codebases with declarative SwiftUI views during gradual migrations or to leverage platform-specific features not yet fully available in SwiftUI. This bidirectional bridging allows SwiftUI apps to wrap UIKit components while also embedding SwiftUI content within traditional UIKit or AppKit hierarchies, preserving access to mature APIs like custom drawing or complex controllers. To incorporate UIKit views into a SwiftUI interface, developers adopt the UIViewRepresentable protocol, which requires implementing makeUIView(context:) to instantiate the view and updateUIView(_:context:) to synchronize changes based on SwiftUI state. For view controllers, UIViewControllerRepresentable follows a similar pattern with makeUIViewController(context:) and updateUIViewController(_:context:). These protocols facilitate the creation of wrappers, such as embedding a UITableView for advanced table behaviors like dynamic cell heights or custom data sources that exceed SwiftUI's List capabilities. In the wrapper for a UITableView, the makeUIView method configures the table view with a delegate and data source, while updateUIView reloads data when the underlying SwiftUI binding changes, ensuring reactive updates without full re-renders. Handling callbacks and delegates from UIKit within SwiftUI often involves the Coordinator pattern, where a nested Coordinator class conforms to the necessary protocols (e.g., UITableViewDelegate or UIPageViewControllerDelegate) and is created via the representable's makeCoordinator() method. The coordinator acts as a bridge, forwarding events back to SwiftUI state—such as updating a @Binding when a user selects a table row—while the UIViewRepresentable's updateUIView method passes the coordinator to the UIKit view for delegation. This pattern minimizes boilerplate and ensures efficient communication, as seen in examples like a paged carousel using UIPageViewController, where the coordinator tracks page transitions and syncs with SwiftUI's declarative state. For macOS, the NSViewRepresentable protocol mirrors UIViewRepresentable, using makeNSView(context:) to create an AppKit view (e.g., an NSOpenGLView for custom OpenGL rendering) and updateNSView(_:context:) for updates driven by SwiftUI properties. Similarly, NSViewControllerRepresentable wraps NSViewController instances, such as a controller managing layered NSView subclasses for complex layouts. Coordinators apply here too, for instance, implementing NSTextViewDelegate in a text editor wrapper to notify SwiftUI of selection changes. A common migration example involves wrapping an NSTableView to reuse existing data-binding logic, where the coordinator handles row selections and the update method refreshes content based on SwiftUI's observable objects. Conversely, to host SwiftUI views within UIKit or AppKit apps, UIHostingController embeds a SwiftUI view as a UIViewController in iOS hierarchies, initialized with the root SwiftUI view and added to a UIKit navigation stack for incremental adoption. On macOS, NSHostingController serves the same purpose for NSViewController integration, while NSHostingView directly wraps a SwiftUI view as an NSView for finer-grained embedding, such as placing a SwiftUI panel within an existing AppKit window. These hosting mechanisms automatically manage the view lifecycle, including state preservation during transitions. Best practices emphasize using wrappers only for legacy components or specialized features unavailable in pure SwiftUI, such as low-level graphics APIs, to avoid unnecessary bridging overhead that can introduce minor performance costs from repeated view updates across framework boundaries. For migrations, start with hosting SwiftUI in existing apps to prototype new features, then progressively replace UIKit/AppKit sections with native SwiftUI equivalents, testing for state synchronization via bindings to prevent inconsistencies. Deep nesting of wrappers should be minimized, as it may amplify redraw latency in complex scenes; instead, favor shallow integrations and profile with Instruments to identify bottlenecks.

Support for visionOS and Other Platforms

SwiftUI provides native support for visionOS, introduced at WWDC 2023 alongside the Apple Vision Pro headset, enabling developers to create spatial applications using familiar declarative syntax integrated with RealityKit for rendering 3D content. In visionOS, SwiftUI facilitates spatial computing through features like volumetric windows, which allow content to extend into 3D space beyond flat screens, and immersive spaces that fill the user's environment for fully enclosed experiences. Users interact via gaze-based selection and hand gestures, with SwiftUI views responding to these inputs through built-in modifiers that handle depth-aware positioning and occlusion. For augmented and virtual reality elements, SwiftUI introduces RealityView, a container that embeds 3D RealityKit content directly into the view hierarchy, supporting anchors for stable placement relative to the real world or other entities. Developers can manipulate entities—such as models or lights—programmatically or via gestures, enabling dynamic interactions like rotating objects with pinch motions while maintaining performance through efficient rendering pipelines. Beyond visionOS, SwiftUI extends to other platforms with specialized adaptations. On watchOS, it supports complications for watch faces since watchOS 9, allowing compact, glanceable data displays using views like Text and Image within WidgetKit timelines. For tvOS, SwiftUI integrates with the focus engine via modifiers such as .focusable() and .focused(), enabling smooth navigation with remote controls across rows and grids in media apps. On macOS, SwiftUI builds menu bar apps through MenuBarExtra, providing persistent status items with dropdown content that responds to user interactions without full window management. Developing for these platforms presents challenges, including managing depth perception in visionOS to avoid disorientation from mismatched spatial cues, and optimizing performance on resource-constrained devices like Apple Watch, where SwiftUI's rendering must balance animations with battery life. Looking ahead, visionOS 2.6 and iOS 19 updates in 2025 expand mixed reality capabilities, introducing enhanced volumetric APIs in SwiftUI for better integration of AR features across devices, such as spatial widgets and layout-aware rotations.

Advanced Topics

Custom Views and Modifiers

Custom views in SwiftUI are created by defining structs that conform to the View protocol, which requires implementing a body computed property to describe the view's content using other views and modifiers. This approach allows developers to encapsulate reusable UI logic, such as a custom button or card component, by composing primitive views like Text or Image within the body. For instance, a simple custom view might stack a title and description as follows:
swift
struct CustomCard: View {
    let title: String
    let description: String
    
    var body: some View {
        VStack {
            Text(title)
                .font(.headline)
            Text(description)
                .font(.subheadline)
        }
        .padding()
        .background(Color.gray.opacity(0.2))
    }
}
This encapsulation promotes modularity and reusability across an app. Custom modifiers extend this flexibility by adopting the ViewModifier protocol, enabling the creation of reusable transformations that can be applied to any view via the .modifier() method. A custom modifier typically defines a body property that wraps the content view and applies changes like padding, shadows, or styling. For example, a border modifier could be implemented as:
swift
struct BorderModifier: ViewModifier {
    let color: Color
    let width: CGFloat
    
    func body(content: Content) -> some View {
        content
            .overlay(
                Rectangle()
                    .stroke(color, lineWidth: width)
            )
    }
}

extension View {
    func bordered(color: Color = .blue, width: CGFloat = 1) -> some View {
        modifier(BorderModifier(color: color, width: width))
    }
}
This pattern allows the modifier to be chained declaratively, such as Text("Hello").bordered(color: .red), fostering consistent styling without duplicating code. The GeometryReader view provides access to layout information, such as the size and position of its parent container, enabling dynamic sizing and positioning of child views. It wraps content in a closure that receives a GeometryProxy, which exposes properties like size, safeAreaInsets, and coordinate spaces for precise control. A common use is centering content relative to the available space:
swift
GeometryReader { geometry in
    Text("Centered")
        .position(x: geometry.size.width / 2, y: geometry.size.height / 2)
}
This tool is essential for adaptive layouts that respond to varying screen sizes without hardcoding values. Preference keys facilitate upward communication in the view hierarchy by allowing child views to propagate data to ancestors, using the PreferenceKey protocol to define custom keys with default values and reduction logic for merging multiple preferences. For example, a custom tab bar might use a preference key to track selected tab indices from child views, enabling the parent to react accordingly via .onPreferenceChange. This mechanism is particularly useful for scenarios like custom navigation or selection feedback without direct parent-child references. Custom drawing in SwiftUI leverages the Shape protocol and Path for declarative vector graphics, where shapes define paths relative to a rectangle and can be filled, stroked, or animated. A Shape struct implements a path(in:) method returning a Path with commands like move(to:), addLine(to:), or addArc. For more imperative control, introduced in iOS 15, the Canvas view supports immediate-mode drawing via a GraphicsContext, allowing pixel-perfect graphics like charts or games by updating content in response to timers or gestures. An example Shape for a custom arrow:
swift
struct Arrow: Shape {
    func path(in rect: CGRect) -> Path {
        var path = Path()
        path.move(to: CGPoint(x: rect.midX, y: rect.minY))
        path.addLine(to: CGPoint(x: rect.minX, y: rect.maxY))
        path.addLine(to: CGPoint(x: rect.maxX, y: rect.maxY))
        path.closeSubpath()
        return path
    }
}
This declarative approach ensures shapes scale and animate smoothly with SwiftUI's layout system. Best practices for custom views and modifiers emphasize purity by treating views as value types that compute their body based solely on properties and environment, avoiding side effects like mutable state mutations or external API calls within the view itself. Instead, delegate such logic to @State, @Binding, or Combine publishers outside the view to maintain predictability and enable SwiftUI's diffing optimizations. Additionally, limit view complexity by breaking into smaller composable units and using @ViewBuilder for flexible content slots, ensuring efficient previews and reduced recomputation during updates.

Performance Optimization

SwiftUI performance optimization focuses on techniques to ensure smooth rendering and responsiveness, particularly in apps handling large datasets or complex user interfaces. Developers can leverage built-in mechanisms to minimize unnecessary computations and resource usage, such as on-demand loading and efficient update detection. These strategies help prevent issues like scrolling hitches or excessive CPU usage, enabling apps to maintain 60 frames per second even under load. Lazy containers like LazyVStack, LazyHStack, and LazyVGrid enable on-demand loading of subviews within scrollable areas, rendering content only as it becomes visible to the user. This approach provides significant performance gains for large collections, reducing initial memory allocation and computation time compared to non-lazy equivalents like VStack or HStack. For instance, in a horizontally scrolling list of profile views, replacing HStack with LazyHStack can limit the number of instantiated views from thousands to just those in the viewport, avoiding runtime slowdowns. Implementing Equatable conformance for custom view structs allows SwiftUI to skip recomputing the view's body if the view's properties remain unchanged between updates. By defining equality based on relevant data, such as model properties, developers can optimize hierarchies where parent views frequently update without affecting child views. This is particularly useful for views with equatable state, reducing the frequency of body evaluations in dynamic UIs. To profile and diagnose performance issues, developers use Xcode's Instruments tool with the SwiftUI template, which tracks view body computations, update frequencies, memory allocations, and GPU rendering. The SwiftUI instrument visualizes update groups, highlighting long-running body updates (e.g., those exceeding 500µs in orange or 1000µs in red) and hitches where rendering deadlines are missed. Time Profiler and flame graphs further identify bottlenecks, such as expensive closures or synchronous operations, while cause-and-effect graphs reveal how data changes propagate through the view hierarchy. In 2025, Instruments introduced an enhanced SwiftUI instrument that details view update triggers from data changes, aiding in pinpointing inefficiencies like redundant redraws. Reducing redraws involves minimizing body computations through stable view identities and avoiding unnecessary state changes. Assigning unique, stable id values via Identifiable or explicit .id() modifiers ensures SwiftUI efficiently diffs and updates only modified parts of the hierarchy, preventing full recomputes. For example, using constant identities in ForEach loops avoids recreating views on data reshuffles. Additionally, caching expensive results asynchronously and applying thresholds to modifiers like onChange limits update triggers, while the Observable macro confines reactivity to specific properties rather than entire objects. These practices complement state management by curbing redraws from frequent minor changes. For lists, optimizations include support for diffable data sources through Identifiable models, enabling efficient incremental updates without reloading the entire collection. Starting in iOS 16, SwiftUI Lists identify rows by their data values when possible, allowing precise insertions, deletions, and animations based on differences. Prefetching for images and content in lists further smooths scrolling by preparing assets ahead of visibility, reducing hitches in data-heavy apps. In 2025 updates, SwiftUI introduced incremental list updates that refine diffing algorithms for faster animations and reduced CPU overhead during data mutations, alongside scrolling scheduler improvements that prioritize UI updates on iOS and macOS for more consistent frame rates. These enhancements, combined with new Instruments capabilities, boost overall framework performance, particularly in lists and scroll views with dynamic content.

Testing and Debugging

SwiftUI provides built-in previews in Xcode for rapid iteration and testing of views during development. These previews render the view hierarchy in real-time alongside the code editor, updating automatically as changes are made. Developers can create parameterized previews using the #Preview macro to simulate different states, such as varying data inputs, themes, or environment configurations, which helps test edge cases without running the full app. For device simulations, previews support specifying traits like screen size, orientation, and dynamic type scaling via previewTraitCollection(_:), enabling verification across multiple Apple devices and accessibility settings. Unit testing SwiftUI views typically leverages the XCTest framework to verify view structure, state changes, and rendered traits. Since SwiftUI views are declarative structs, direct assertions on their properties can be made by instantiating the view in a test and inspecting its body or environment values. For more comprehensive hierarchy inspection, the third-party ViewInspector library enables runtime traversal of the view tree, allowing assertions on child views, modifiers, and dynamic content without rendering to a screen. This approach supports custom assertions for traits like accessibility labels or layout properties, ensuring views behave correctly under specific conditions. UI testing in SwiftUI apps integrates seamlessly with XCUITest, Apple's framework for automating user interactions on the device or simulator. Tests can launch the app, query elements by accessibility identifiers—which SwiftUI views expose via .accessibilityIdentifier(_:)—and simulate taps, swipes, or text entry to validate interaction flows. This is particularly useful for end-to-end scenarios, such as navigation between views or form submissions, and includes built-in support for accessibility checks like voiceover readability and dynamic type compliance. In 2025, Xcode enhancements allow recording and replaying XCUITests across diverse locales, device types, and system conditions to catch platform-specific regressions. Debugging SwiftUI involves tools to trace view updates and inspect runtime behavior. The internal method Self._printChanges() can be called within a view's body to log the properties triggering re-renders, helping identify unnecessary updates due to state changes or environment shifts. For visionOS apps, Reality Composer Pro aids in debugging spatial layouts by allowing composition and preview of 3D assets integrated with SwiftUI's RealityView, revealing mismatches in entity hierarchies or gesture interactions in immersive spaces. Additionally, Instruments provides templates like SwiftUI Trace for profiling update cycles and detecting hitches. Common issues in SwiftUI include hierarchy mismatches, where expected child views fail to render due to conditional logic or data binding errors, often resolved by using explicit if statements or Group wrappers to stabilize the view identity. Gesture conflicts arise when multiple recognizers, such as DragGesture and TapGesture, compete on the same view; resolution involves prioritizing via highPriorityGesture(_:) or sequencing with simultaneousGesture(_:), ensuring the intended interaction takes precedence without blocking others. State-related bugs, like unexpected re-renders, may reference performance metrics but are best isolated using _printChanges() to pinpoint reactive dependencies. In 2025, SwiftUI testing and debugging saw enhancements including improved Instruments profiling for list views, which now offers granular traces of lazy loading and diffing algorithms to detect rendering bottlenecks in large datasets. Xcode 26 introduced advanced debugging workflows, such as AI-assisted breakpoint suggestions and enhanced test coverage visualization for SwiftUI hierarchies. For visionOS, Liquid Glass—a new translucent material for UI elements—requires testing in Instruments to prevent visual artifacts in spatial interfaces.

Examples

Simple User Interface

A simple user interface in SwiftUI can be created with minimal code to display static text and handle basic user interaction, such as a button tap that updates a counter. This demonstrates the framework's declarative nature, where the user interface is described as a function of state rather than through imperative commands. The entry point for a SwiftUI app is defined using a struct that conforms to the App protocol, marked with the @main attribute to indicate it as the program's starting point. The body property of this struct returns a Scene, typically a WindowGroup that hosts the root view, such as ContentView. This structure manages the app's lifecycle, initializing the window and rendering the view hierarchy upon launch. Here is a complete minimal app example in Swift, assuming an iOS project created in Xcode: MyApp.swift:
swift
import SwiftUI

@main
struct MyApp: App {
    var body: some Scene {
        WindowGroup {
            ContentView()
        }
    }
}
ContentView.swift:
swift
import SwiftUI

struct ContentView: View {
    @State private var tapCount = 0
    
    var body: some View {
        VStack {
            Text("Hello, SwiftUI!")
                .font(.largeTitle)
            
            Text("Button tapped \(tapCount) times")
                .font(.title2)
            
            Button("Tap Me") {
                tapCount += 1
            }
            .padding()
            .background(Color.blue)
            .foregroundColor(.white)
            .cornerRadius(10)
        }
        .padding()
    }
}
In this example, ContentView conforms to the View protocol, with its body computed property returning a view hierarchy composed of a VStack containing Text views and a Button. The @State property wrapper manages the tapCount as mutable state local to the view; when the button's action closure increments it, SwiftUI automatically recomputes and updates the relevant parts of the UI to reflect the change. To preview the view during development, add a #Preview macro at the end of ContentView.swift. This enables Xcode's canvas to render a live preview of ContentView without building the full app, updating in real-time as code changes. The preview requires Xcode 15 or later and macOS Sonoma or later.
swift
#Preview {
    ContentView()
}
To run the app on a simulator, open the project in Xcode, select an iOS simulator from the device menu (e.g., iPhone 15), and press Command-R or click the Run button. Xcode builds the app, launches the simulator, and displays the interface; interactions like button taps update the counter in real-time. Variations can enhance the basic layout with view modifiers. For instance, applying .padding() adds spacing around the VStack for better visual separation, while .foregroundColor(.green) changes the text color to green, demonstrating how modifiers chain to customize appearance without altering the core structure. Updated body example with variations:
swift
var body: some View {
    VStack {
        Text("Hello, SwiftUI!")
            .font(.largeTitle)
            .foregroundColor(.green)
        
        Text("Button tapped \(tapCount) times")
            .font(.title2)
        
        Button("Tap Me") {
            tapCount += 1
        }
        .padding()
        .background(Color.blue)
        .foregroundColor(.white)
        .cornerRadius(10)
    }
    .padding()  // Adds outer padding to the entire stack
}

Data-Driven Application

A data-driven application in SwiftUI demonstrates how declarative views respond to changing data sources, such as network-fetched JSON, through modern property wrappers like @State and the @Observable macro (iOS 17 and later). Consider a todo list app where tasks are initially loaded from a remote JSON file via URLSession, users can add or delete items, and navigation leads to a detail view for editing. This setup uses an @Observable model to manage the todo array, ensuring the UI updates automatically when data changes. The core model begins with a Todo struct that conforms to Identifiable and Codable for serialization:
swift
struct Todo: Identifiable, Codable {
    let id = UUID()
    var title: String
    var isCompleted: Bool = false
}
A view model class, TodoViewModel, uses the @Observable macro to expose mutable data (iOS 17+):
swift
import SwiftUI
import Observation

@Observable
@MainActor
class TodoViewModel {
    var todos: [Todo] = []
    var searchText = ""
    var isLoading = false
    var error: Error?
    
    var filteredTodos: [Todo] {
        if searchText.isEmpty {
            return todos
        } else {
            return todos.filter { &#36;0.title.localizedCaseInsensitiveContains(searchText) }
        }
    }
}
In the main view, TodoListView, instantiate the view model with @State to observe changes, and use a List containing ForEach to render rows. Each row wraps a NavigationLink to a detail view, TodoDetailView, passing the selected todo's ID. The view model is provided via the environment for access in child views:
swift
struct TodoListView: View {
    @State private var viewModel = TodoViewModel()
    
    private var searchBinding: Binding<String> {
        Binding(
            get: { viewModel.searchText },
            set: { viewModel.searchText = &#36;0 }
        )
    }
    
    var body: some View {
        NavigationStack {
            if viewModel.isLoading {
                ProgressView("Loading todos...")
            } else if let error = viewModel.error {
                Text("Error: \(error.localizedDescription)")
            } else {
                List {
                    ForEach(viewModel.filteredTodos) { todo in
                        NavigationLink {
                            TodoDetailView(todoId: todo.id)
                        } label: {
                            TodoRowView(todo: todo)
                        }
                    }
                    .onDelete(perform: viewModel.deleteTodos)
                }
                .navigationTitle("Todos")
                .searchable(text: searchBinding, prompt: "Search todos")
                .toolbar {
                    ToolbarItem(placement: .navigationBarTrailing) {
                        Button("Add Todo") {
                            let newTodo = Todo(title: "New Task")
                            viewModel.todos.append(newTodo)
                        }
                    }
                }
            }
        }
        .task {
            await viewModel.fetchTodos()
        }
        .environment(viewModel)
    }
}
The TodoRowView displays the title and completion status. The TodoDetailView allows editing the todo's properties and updates the model via a dedicated method, enabling two-way data flow:
swift
struct TodoDetailView: View {
    let todoId: UUID
    @Environment(TodoViewModel.self) private var viewModel
    @State private var title: String = ""
    @State private var isCompleted = false
    
    var body: some View {
        Form {
            TextField("Title", text: $title)
            Toggle("Completed", isOn: $isCompleted)
            Button("Save") {
                viewModel.updateTodo(id: todoId, title: title, isCompleted: isCompleted)
            }
        }
        .navigationTitle("Edit Todo")
        .onAppear {
            if let todo = viewModel.todos.first(where: { &#36;0.id == todoId }) {
                title = todo.title
                isCompleted = todo.isCompleted
            }
        }
    }
}

struct TodoRowView: View {
    let todo: Todo
    
    var body: some View {
        HStack {
            Text(todo.title)
            Spacer()
            if todo.isCompleted {
                Image(systemName: "checkmark.circle.fill")
                    .foregroundColor(.green)
            }
        }
    }
}
Adding or deleting items updates the todos array directly, triggering view recomputation without manual invalidation. For asynchronous integration, the fetch occurs in the view model's fetchTodos() method, leveraging Swift 5.5's async/await (iOS 15+). This uses Task { } or the .task modifier to perform non-blocking network calls with URLSession. The NavigationStack requires iOS 16+.
swift
extension TodoViewModel {
    func fetchTodos() async {
        isLoading = true
        error = nil
        guard let url = URL(string: "https://example.com/todos.json") else { return }
        do {
            let (data, _) = try await URLSession.shared.data(from: url)
            todos = try JSONDecoder().decode([Todo].self, from: data)
        } catch {
            self.error = error
            todos = []
        }
        isLoading = false
    }
    
    func deleteTodos(at offsets: IndexSet) {
        todos.remove(atOffsets: offsets)
    }
    
    func updateTodo(id: UUID, title: String, isCompleted: Bool) {
        if let index = todos.firstIndex(where: { &#36;0.id == id }) {
            todos[index] = Todo(id: id, title: title, isCompleted: isCompleted)
        }
    }
}
A loading indicator appears via ProgressView while isLoading is true, and errors are handled by displaying a localized message, ensuring a resilient user experience. This approach avoids blocking the main thread, aligning with SwiftUI's concurrency model. For persistence, integrate Core Data by defining a Todo entity in the data model with attributes like title and isCompleted. Use @FetchRequest in the view to query the managed object context, which is provided via the environment. Here, Todo refers to an NSManagedObject subclass:
swift
struct TodoListView: View {
    @Environment(\.managedObjectContext) private var viewContext
    @FetchRequest(
        sortDescriptors: [NSSortDescriptor(keyPath: \Todo.title, ascending: true)],
        animation: .default)
    private var todos: FetchedResults<Todo>

    var body: some View {
        List {
            ForEach(todos) { todo in
                // Row view, e.g., TodoRowView(todo: todo)
            }
            .onDelete(perform: deleteTodos)
        }
    }
    
    private func deleteTodos(offsets: IndexSet) {
        withAnimation {
            offsets.map { todos[&#36;0] }.forEach(viewContext.delete)
            do {
                try viewContext.save()
            } catch {
                // Handle error
            }
        }
    }
}
This replaces the @Published or observed array, automatically syncing UI changes with the persistent store without deep configuration details. For editing in Core Data, the Todo managed object provides reference semantics, allowing direct binding to its properties in detail views.

References

  1. [1]
    SwiftUI - Latest News - Apple Developer
    Jun 3, 2019 · SwiftUI is an innovative new way to build user interfaces across all Apple platforms, so you can create better apps with less code.
  2. [2]
    Introducing SwiftUI | Apple Developer Documentation
    SwiftUI is a modern way to declare user interfaces for any Apple platform. Create beautiful, dynamic apps faster than ever before.Introduction to SwiftUI · Creating and combining views · View fundamentals
  3. [3]
    Introducing SwiftUI: Building Your First App - WWDC19 - Videos
    May 24, 2019 · Watch as engineers from the SwiftUI team build a fully-functioning app from scratch. Understand the philosophy driving this new framework.
  4. [4]
    SwiftUI | Apple Developer Documentation
    SwiftUI provides views, controls, and layout structures for declaring your app's user interface. The framework provides event handlers for delivering taps, ...SwiftUI Concepts Tutorials · SwiftUI updates · Documents · Navigation
  5. [5]
    Exploring the structure of a SwiftUI app - Apple Developer
    SwiftUI is a declarative framework that helps you compose the user interface of your app. The principle building blocks that form the structure of a SwiftUI app ...
  6. [6]
    Get Started - SwiftUI - Apple Developer
    SwiftUI's combination of declarative syntax, live previews, and multi-device support provides everything you need to begin designing and developing for ...Meet SwiftUI · Seek out the best view · Plan for navigation
  7. [7]
    SwiftUI essentials - WWDC24 - Videos - Apple Developer
    Jun 10, 2024 · Join us on a tour of SwiftUI, Apple's declarative user interface framework. Learn essential concepts for building apps in SwiftUI.
  8. [8]
    What's New - SwiftUI - Apple Developer
    SwiftUI on visionOS​​ New APIs enable you to enhance windows, volumes, and immersive spaces in your visionOS app. With SwiftUI spatial layout, you get support ...
  9. [9]
    SwiftUI - Apple Developer
    A MacBook Pro, iPad, and iPhone, each displaying the SwiftUI interface. Get to know SwiftUI.SwiftUI essentials · Get Started · Resources · What’s New
  10. [10]
    SwiftUI | Apple Developer Documentation
    SwiftUI provides views, controls, and layout structures for declaring your app's user interface. The framework provides event handlers for delivering taps, ...Learning SwiftUI · Documents · SwiftUI updates · View
  11. [11]
    Previewing SwiftUI views in Swift Playgrounds - Apple Developer
    In Swift Playgrounds, you can see live Previews of your SwiftUI views just like Previews in Xcode. In an app playground, you have a default App Preview.Missing: real- time
  12. [12]
    Driving changes in your UI with state and bindings - Apple Developer
    This approach helps make the declarative interface code of a view more readable by moving properties and imperative code outside of the view. It also helps ...
  13. [13]
    State | Apple Developer Documentation
    Use state as the single source of truth for a given value type that you store in a view hierarchy. Create a state value in an App, Scene, or View.
  14. [14]
    Binding | Apple Developer Documentation
    Use a binding to create a two-way connection between a property that stores data, and a view that displays and changes the data.
  15. [15]
    Previews in Xcode | Apple Developer Documentation
    When you create a custom View with SwiftUI, Xcode can display a preview of the view's content that stays up-to-date as you make changes to the view's code.Missing: live iterative development
  16. [16]
    Apple unveils groundbreaking new technologies for app development
    PRESS RELEASE June 3, 2019. Apple unveils groundbreaking new technologies for app development. Breakthrough SwiftUI Framework, ARKit 3 and New Xcode Tools ...
  17. [17]
    Apple Announces Declarative SwiftUI Framework for Leaner, Faster ...
    Jun 5, 2019 · Apple recently announced at WWDC 2019 the SwiftUI framework for application development across the iOS, macOS, tvOS, and watchOS platforms.
  18. [18]
    Xcode 11 Release Notes | Apple Developer Documentation
    Xcode 11 supports development with SwiftUI. (22843503). Note. SwiftUI previews and inspectors are only available when running on macOS Catalina 10.15. Xcode ...<|control11|><|separator|>
  19. [19]
    iOS 13: Complete Guide and Feature List - MacRumors
    Sep 1, 2020 · Apple released the iOS 13 update on Thursday, September 19 after several months of beta testing. The update was followed shortly after by iOS ...What's New in iOS 13 · Dark Mode · iOS 13 Features · Hidden iOS Tips and Tricks
  20. [20]
    SwiftUI updates | Apple Developer Documentation
    Learn about important changes to SwiftUI ... Overview ... Browse notable changes in SwiftUI ... June 2025 ... General ... Text ... Accessibility ... HDR ... UIKit and AppKit ...
  21. [21]
    What's new in SwiftUI - WWDC20 - Videos - Apple Developer
    SwiftUI can help you build better and more powerful apps for iPhone, iPad, Mac, Apple Watch, and Apple TV. Learn more about the latest...
  22. [22]
    WWDC20 highlights - Apple
    Jun 26, 2020 · This week we've been showcasing the biggest moments from WWDC20, including highlights from developer sessions, the most talked-about demos, the newest design ...Play: Explore The Action And... · Play: Tap Into Game Center... · Play: Detect Body And Hand...
  23. [23]
    What's new in SwiftUI - WWDC21 - Videos - Apple Developer
    including lists, buttons, and text fields — and learn how these features can help you more fully adopt SwiftUI ...
  24. [24]
    What's new in SwiftUI - WWDC22 - Videos - Apple Developer
    Jun 6, 2022 · We introduced SwiftUI's layout model with the first release ... flatMap { $0 } // MARK: Date Utilities extension Date { static func daysAgo ...
  25. [25]
    What's new in SwiftUI - WWDC23 - Videos - Apple Developer
    Jun 6, 2023 · Learn how you can use SwiftUI to build great apps for all Apple platforms. Explore the latest updates to SwiftUI and discover new scene types for visionOS.
  26. [26]
    iOS & iPadOS 18 Release Notes | Apple Developer Documentation
    New Features · When using a TabView , tapping on the current tab now pops any embedded navigation stack. · Pickers now can have keyboard shortcuts attached to ...
  27. [27]
    What's new in SwiftUI - WWDC25 - Videos - Apple Developer
    Jun 9, 2025 · Learn what's new in SwiftUI to build great apps for any Apple platform. We'll explore how to give your app a brand new look and feel with Liquid Glass.
  28. [28]
    Apple introduces a delightful and elegant new software design
    Jun 9, 2025 · Apple previewed a new software design, crafted with Liquid Glass, that makes apps and system experiences more expressive and delightful.Apple (CA) · Apple (AU) · Apple (IL) · Apple (NZ)<|separator|>
  29. [29]
    View fundamentals | Apple Developer Documentation
    Configure views using the view modifiers that SwiftUI provides, or by defining your own view modifiers using the ViewModifier protocol and the modifier(_:) ...
  30. [30]
    View | Apple Developer Documentation
    You create custom views by declaring types that conform to the View protocol. Implement the required body computed property to provide the content for your ...View fundamentals · Declaring a custom view · TabView · ProgressView
  31. [31]
    Understanding and improving SwiftUI performance - Apple Developer
    SwiftUI implements a declarative approach to constructing a user interface. You describe your app's UI and how it depends on the app's data and environment.
  32. [32]
    UIKit integration | Apple Developer Documentation
    Add UIKit views to your SwiftUI app, or use SwiftUI views in your UIKit app.
  33. [33]
    body | Apple Developer Documentation
    When you implement a custom view, you must implement a computed body property to provide the content for your view. Return a view that's composed of built-in ...
  34. [34]
    padding(_:_:) | Apple Developer Documentation
    Use this modifier to add a specified amount of padding to one or more edges of the view. Indicate the edges to pad by naming either a single value from Edge. ...Missing: background | Show results with:background
  35. [35]
  36. [36]
    Identifiable | Apple Developer Documentation
    A class of types whose instances hold the value of an entity with stable identity.
  37. [37]
    Working with Identifiable items in SwiftUI - a free Hacking with iOS
    Apr 11, 2024 · SwiftUI needs to know how it can identify each item uniquely otherwise it will struggle to compare view hierarchies to figure out what has changed.
  38. [38]
    Preview(_:body:) | Apple Developer Documentation
    Overview. Use this macro to display a SwiftUI preview in the canvas. You typically specify at least one preview macro for every View that your app defines to ...
  39. [39]
    Previewing your app's interface in Xcode - Apple Developer
    Overview. With Swift previews, you can make changes to your app's views in code, and see the result of those changes quickly in the preview canvas.
  40. [40]
    Managing user interface state | Apple Developer Documentation
    SwiftUI watches for changes in the data, and updates any affected views as needed. A diagram showing state stored in one view, shared with another view through ...
  41. [41]
    ObservedObject | Apple Developer Documentation
    ### Summary of @ObservedObject and its Use with ObservableObject Protocol
  42. [42]
    ObservableObject | Apple Developer Documentation
    An ObservableObject synthesizes an objectWillChange publisher that emits the changed value before any of its @Published properties changes.
  43. [43]
    Migrating from the Observable Object protocol to ... - Apple Developer
    To adopt Observation in an existing app, begin by replacing ObservableObject in your data model type with the Observable() macro.
  44. [44]
    EnvironmentObject | Apple Developer Documentation
    Overview. An environment object invalidates the current view whenever the observable object that conforms to ObservableObject changes.
  45. [45]
  46. [46]
    Text | Apple Developer Documentation
    A text view draws a string in your app's user interface using a body font that's appropriate for the current platform.Text.Layout · Init(_:) · Init(verbatim:) · Tracking(_:)
  47. [47]
    Label | Apple Developer Documentation
    You create a label, in its simplest form, by providing a title and the name of an image, such as an icon from the SF Symbols collection.
  48. [48]
    Image | Apple Developer Documentation
    A view that displays an image ... SwiftUI · Swift Playground · TestFlight · Xcode · Xcode Cloud · SF Symbols. Topics & Technologies. Toggle Menu. Accessibility ...
  49. [49]
    AsyncImage | Apple Developer Documentation
    A view that asynchronously loads and displays an image.
  50. [50]
    AsyncImagePhase | Apple Developer Documentation
    When you create an AsyncImage instance with the init(url:scale:transaction:content:) initializer, you define the appearance of the view using a content closure.
  51. [51]
    Button | Apple Developer Documentation
    ### Summary of Button in SwiftUI
  52. [52]
    Toggle | Apple Developer Documentation
    Overview. You create a toggle by providing an isOn binding and a label. Bind isOn to a Boolean property that determines whether the toggle is on or off.
  53. [53]
    Slider | Apple Developer Documentation
    A slider consists of a “thumb” image that the user moves between two extremes of a linear “track”. The ends of the track represent the minimum and maximum ...
  54. [54]
    List | Apple Developer Documentation
    A container that presents rows of data arranged in a single column, optionally providing the ability to select one or more members.
  55. [55]
    Form | Apple Developer Documentation
    SwiftUI applies platform-appropriate styling to views contained inside a form, to group them together. Form-specific styling applies to things like buttons, ...
  56. [56]
    ProgressView | Apple Developer Documentation
    A view that shows the progress toward completion of a task.
  57. [57]
    Alert | Apple Developer Documentation
    Use an alert when you want the user to act in response to the state of the app or system. If you want the user to make a choice in response to their action, use ...
  58. [58]
  59. [59]
    Chart | Apple Developer Documentation
    Make a chart by combining chart building blocks in SwiftUI. Visualizing your app's data. Build complex and interactive charts using Swift Charts.<|control11|><|separator|>
  60. [60]
    MapKit for SwiftUI | Apple Developer Documentation
    MapKit for SwiftUI allows you to build map-centric views and apps across Apple platforms. You can design expressive and highly interactive Maps with minimal ...
  61. [61]
    Building layouts with stack views | Apple Developer Documentation
    Compose complex layouts from primitive container views.
  62. [62]
    VStack | Apple Developer Documentation
    A VStack renders the views all at once, regardless of whether they are on- or offscreen. Use the regular VStack when you have a small number of subviews.
  63. [63]
    Organizing and aligning content with stacks - Apple Developer
    This tutorial walks through using stacks to align content in rows and columns. It also uses stacks to create graphic elements that help organize information.Organizing And Aligning... · Manage Related Data With A... · Add A Background With...
  64. [64]
    LazyVGrid | Apple Developer Documentation
    Use a lazy vertical grid when you want to display a large, vertically scrollable collection of views arranged in a two dimensional layout.
  65. [65]
    LazyHGrid | Apple Developer Documentation
    Use a lazy horizontal grid when you want to display a large, horizontally scrollable collection of views arranged in a two dimensional layout.
  66. [66]
    NavigationStack | Apple Developer Documentation
    Use a navigation stack to present a stack of views over a root view. People can add views to the top of the stack by clicking or tapping a NavigationLink , and ...Missing: NavigationView | Show results with:NavigationView
  67. [67]
  68. [68]
    Migrating to new navigation types | Apple Developer Documentation
    Improve navigation behavior in your app by replacing navigation views with navigation stacks and navigation split views.
  69. [69]
  70. [70]
  71. [71]
    ScrollView | Apple Developer Documentation
    ScrollView can scroll horizontally, vertically, or both, but does not provide zooming functionality. In the following example, a ScrollView allows the user to ...
  72. [72]
    Scroll views | Apple Developer Documentation
    Overview. When the content of a view doesn't fit in the display, you can wrap the view in a ScrollView to enable people to scroll on one or more axes.
  73. [73]
    NavigationSplitView | Apple Developer Documentation
    Overview. You create a navigation split view with two or three columns, and typically use it as the root view in a Scene . People choose one or more items ...Navigationsplitview · Overview · Customize A Split ViewMissing: window | Show results with:window
  74. [74]
    Bringing multiple windows to your SwiftUI app - Apple Developer
    Bringing multiple windows to your SwiftUI app. Compose rich views by reacting to state changes and customize your app's scene presentation and behavior on ...Missing: split | Show results with:split
  75. [75]
  76. [76]
  77. [77]
    Combine | Apple Developer Documentation
    The Combine framework provides a declarative Swift API for processing values over time. These values can represent many kinds of asynchronous events.Using Combine for Your App’s... · Future · Publisher · SubjectMissing: state | Show results with:state
  78. [78]
    Using Combine for Your App's Asynchronous Code - Apple Developer
    Using Combine for Your App's Asynchronous Code. Apply common patterns to migrate your closure-based, event-handling code.Missing: integration | Show results with:integration
  79. [79]
    Published | Apple Developer Documentation
    A type alias for the Combine framework's type for an object with a publisher that emits before the object has changed.
  80. [80]
    Managing model data in your app | Apple Developer Documentation
    With Observation, a view in SwiftUI can form dependencies on observable data models and update the UI when data changes. Note. Observation support in SwiftUI is ...
  81. [81]
    URLSession.DataTaskPublisher | Apple Developer Documentation
    Mentioned in · Processing URL session data task results with Combine · Topics · Creating a data task publisher · init(request: URLRequest, session: URLSession).Missing: example | Show results with:example
  82. [82]
    Processing URL session data task results with Combine
    The following example combines both these operators to parse JSON data from a URL endpoint into a custom User type: struct User: Codable { let name: String let ...
  83. [83]
    Result | Apple Developer Documentation
    Creates a new result by evaluating a throwing closure, capturing the returned value as a success, or any thrown error as a failure.
  84. [84]
    Observation | Apple Developer Documentation
    Observation provides a robust, type-safe, and performant implementation of the observer design pattern in Swift. This pattern allows an observable object to ...
  85. [85]
    Configuring a multiplatform app | Apple Developer Documentation
    In Xcode 14 or later, you can share your app's project settings and code across platforms using a single, multiplatform target.
  86. [86]
    Mac Catalyst | Apple Developer Documentation
    May 2, 2023 · In contrast, keyboard and mouse interactions inform most macOS conventions. Most iPadOS gestures convert automatically when you create your Mac ...
  87. [87]
    Building Widgets Using WidgetKit and SwiftUI - Apple Developer
    Building Widgets Using WidgetKit and SwiftUI ... Create widgets to show your app's content on the Home screen, with custom intents for user-customizable settings.Missing: integration | Show results with:integration
  88. [88]
    Support directional remotes in your tvOS app - Apple Developer
    May 10, 2021 · All standard gestures in tvOS work with directional remotes by default, and you can also provide support in your app for custom gestures with classes like ...
  89. [89]
    Gestures | Apple Developer Documentation
    A gesture is a physical motion that a person uses to directly affect an object in an app or game on their device.
  90. [90]
    Running code on a specific platform or OS version - Apple Developer
    In Swift, use the #available compiler control statement to run code conditionally. In Objective-C, use the @available compiler directive to run code ...
  91. [91]
    AppKit integration | Apple Developer Documentation
    Overview. Integrate SwiftUI with your app's existing content using hosting controllers to add SwiftUI views into AppKit interfaces.
  92. [92]
    Interfacing with UIKit — SwiftUI Tutorials - Apple Developer
    To represent UIKit views and view controllers in SwiftUI, you create types that conform to the UIViewRepresentable and UIViewControllerRepresentable protocols.Missing: AppKit | Show results with:AppKit
  93. [93]
    UIViewRepresentable | Apple Developer Documentation
    Use a UIViewRepresentable instance to create and manage a UIView object in your SwiftUI interface. Adopt this protocol in one of your app's custom instances.
  94. [94]
    UIViewControllerRepresentable | Apple Developer Documentation
    Use a UIViewControllerRepresentable instance to create and manage a UIViewController object in your SwiftUI interface.
  95. [95]
  96. [96]
    NSViewControllerRepresentable | Apple Developer Documentation
    NSViewControllerRepresentable. A wrapper that you use to integrate an AppKit view controller into your SwiftUI interface. macOS 10.15+.
  97. [97]
    Integrating AppKit — App Dev Tutorials - Apple Developer
    In this article, you'll learn to take advantage of the interoperability features between these two UI frameworks so that you can combine the best features of ...
  98. [98]
    UIHostingController | Apple Developer Documentation
    Overview. Create a UIHostingController object when you want to integrate SwiftUI views into a UIKit view hierarchy. At creation time, specify the SwiftUI ...Missing: NSHostingView | Show results with:NSHostingView
  99. [99]
    NSHostingController | Apple Developer Documentation
    Create an NSHostingController object when you want to integrate SwiftUI views into an AppKit view hierarchy. At creation time, specify the SwiftUI view you want ...Missing: UIHostingController | Show results with:UIHostingController
  100. [100]
    NSHostingView | Apple Developer Documentation
    A hosting view is an NSView object that manages a single SwiftUI view, which may itself contain other SwiftUI views.Missing: UIHostingController | Show results with:UIHostingController
  101. [101]
    Use SwiftUI with UIKit - WWDC22 - Videos - Apple Developer
    Learn how to take advantage of the power of SwiftUI in your UIKit app. Build custom UICollectionView and UITableView cells seamlessly with SwiftUI using ...Missing: AppKit | Show results with:AppKit
  102. [102]
    visionOS - Apple Developer
    Spatial computing. A spectrum of immersion · SwiftUI. Build beautiful, compelling apps · RealityKit. Add depth and dimension · ARKit. Understand your surroundings.
  103. [103]
    visionOS | Apple Developer Documentation
    From there, add SwiftUI scene types specific to visionOS, such as volumes and spaces. These scene types let you incorporate depth, 3D objects, and immersive ...
  104. [104]
    Immersive spaces | Apple Developer Documentation
    Use an immersive space in visionOS to present SwiftUI views outside of any containers. You can include any views in a space.
  105. [105]
    Set the scene with SwiftUI in visionOS - WWDC25 - Videos
    Jun 9, 2025 · Discover exciting new APIs to enhance windows, volumes, and immersive spaces in your visionOS app. Fine tune the behavior of your scenes when relaunched or ...
  106. [106]
    Adding 3D content to your app | Apple Developer Documentation
    When you're ready to display 3D content in your interface, use a RealityView . This SwiftUI view serves as a container for your RealityKit content, and lets you ...
  107. [107]
  108. [108]
    Entity | Apple Developer Documentation
    For example, you typically start by creating an instance of AnchorEntity to anchor your content, and add the anchor to a scene's anchors collection. You ...Entity.ConfigurationCatalog · Entity.ComponentSet · AnchorEntity · ModelEntity
  109. [109]
    Build complications in SwiftUI - WWDC20 - Videos - Apple Developer
    Once you've discovered how to build graphic complications in SwiftUI, you can combine this with other watchOS 7 features like multiple complications and Face ...
  110. [110]
    Focus | Apple Developer Documentation
    Focus indicates which element in the display receives the next input. Use view modifiers to indicate which views can receive focus, to detect which view has ...
  111. [111]
    Building and customizing the menu bar with SwiftUI - Apple Developer
    On iPadOS and macOS, the menu bar provides access to crucial system-provided actions, such as Cut, Copy, Paste, and window management.Missing: complications engine
  112. [112]
    Analyzing the performance of your visionOS app - Apple Developer
    Use the RealityKit Trace template in Instruments to evaluate and improve the performance of your visionOS app.Missing: depth perception Watch
  113. [113]
    What's new in visionOS 26 - WWDC25 - Videos - Apple Developer
    Jun 9, 2025 · Explore exciting new features in visionOS 26. Discover enhanced volumetric APIs and learn how you can combine the power of SwiftUI, RealityKit and ARKit.
  114. [114]
    Declaring a custom view | Apple Developer Documentation
    in this case, the behavior of an element that SwiftUI draws onscreen.
  115. [115]
    ViewModifier | Apple Developer Documentation
    Overview. Adopt the ViewModifier protocol when you want to create a reusable modifier that you can apply to any view. The example below combines several ...
  116. [116]
    modifier(_:) | Apple Developer Documentation
    Use this modifier to combine a View and a ViewModifier, to create a new view. For example, if you create a view modifier for a new kind of caption.
  117. [117]
    GeometryReader | Apple Developer Documentation
    GeometryReader. A container view that defines its content as a function of its own size and coordinate space. iOS 13.0+ ...
  118. [118]
    PreferenceKey | Apple Developer Documentation
    To submit feedback on documentation, visit Feedback Assistant. Select a color scheme preference. Light. Dark. Auto.
  119. [119]
    Preferences | Apple Developer Documentation
    When you use the PreferenceKey protocol to define a custom preference, you indicate how to merge preferences from multiple subviews. You can then set a value ...
  120. [120]
  121. [121]
    Path | Apple Developer Documentation
    Drawing a path ... Begins a new subpath at the specified point. ... Adds an arc of a circle to the path, specified with a radius and angles. ... Adds an arc of a ...
  122. [122]
    Canvas | Apple Developer Documentation
    Use a canvas to draw rich and dynamic 2D graphics inside a SwiftUI view. The canvas passes a GraphicsContext to the closure that you use to perform immediate ...
  123. [123]
    Building Custom Views with SwiftUI - WWDC19 - Apple Developer
    Learn how to build custom views and controls in SwiftUI with advanced composition, layout, graphics, and animation.
  124. [124]
  125. [125]
    Creating performant scrollable stacks - Apple Developer
    Horizontal and vertical stacks are a good solution for repeating views or groups of views, but they don't have a built-in mechanism for scrolling.<|control11|><|separator|>
  126. [126]
  127. [127]
  128. [128]
    Optimize SwiftUI performance with Instruments - WWDC25 - Videos
    Jun 9, 2025 · When I compare with a similar SwiftUI app that does the same thing, I ... WWDC. Get the Apple Developer app. Light. Dark. Auto. English, 简体中文 · 日本語 ...Missing: diffing | Show results with:diffing
  129. [129]
    Demystify SwiftUI performance - WWDC23 - Videos - Apple Developer
    Jun 8, 2023 · Learn how you can build a mental model for performance in SwiftUI and write faster, more efficient code.
  130. [130]
    Updating collection views using diffable data sources
    Building high-performance lists and collection views. Improve the performance of lists and collections in your app with prefetching and image preparation.
  131. [131]
  132. [132]
    Structure your app for SwiftUI previews - WWDC20 - Apple Developer
    When you use SwiftUI previews during development, you can quickly create apps that are more flexible and maintainable. Discover ways to improve the preview ...
  133. [133]
    XCTest | Apple Developer Documentation
    Overview. Use the XCTest framework to write unit tests for your Xcode projects that integrate seamlessly with Xcode's testing workflow.
  134. [134]
    nalexn/ViewInspector: Runtime introspection and unit ... - GitHub
    ViewInspector is a library for unit testing SwiftUI views. It allows for traversing a view hierarchy at runtime providing direct access to the underlying View ...Issues 44 · Pull requests 0 · Discussions · Releases 20
  135. [135]
    Record, replay, and review: UI automation with Xcode - WWDC25
    Jun 9, 2025 · Learn to record, run, and maintain XCUIAutomation tests in Xcode. Replay your XCTest UI tests in dozens of locales, device types, and system conditions.
  136. [136]
    Debugging an App Playground using the Console - Apple Developer
    Another approach that's particularly useful when debugging SwiftUI view updates is to call the internal method Self._printChanges() from the body of the view — ...
  137. [137]
    Get Started - visionOS - Apple Developer
    Create for visionOS · Get the proper tools · Add a new dimension to your interface · Devise straightforward interactions · Create next-level audio and video.
  138. [138]
    Understanding the visionOS render pipeline - Apple Developer
    Use the RealityKit Trace template in Instruments to profile your app and identify workflows with dropped frames and other rendering and responsiveness ...<|separator|>
  139. [139]
    Preferring one gesture over another | Apple Developer Documentation
    Overview. For any two gesture recognizers involved in a potential conflict, only one needs an associated delegate object, and that object must conform to ...
  140. [140]
    What's new in Xcode 26 - WWDC25 - Videos - Apple Developer
    Jun 9, 2025 · Explore editing and debugging enhancements, improved performance and testing tools, and Swift Build - the open-source build system engine used by Xcode.<|control11|><|separator|>
  141. [141]
  142. [142]
  143. [143]
    Update the UI with state — Develop in Swift Tutorials
    Explore how @State properties and buttons work to update the UI of your app by creating an app to roll virtual dice.
  144. [144]
    Creating and combining views — SwiftUI Tutorials - Apple Developer
    Set the preview back to Live mode. Working in Live mode makes it easy to keep track of view behavior as you make edits in source.
  145. [145]
    Hello, SwiftUI | Apple Developer Documentation
    Get to know Xcode, Swift, and SwiftUI ... Tutorials · Downloads · Forums · Videos. Support. Toggle Menu. Support Articles ...
  146. [146]
    Building lists and navigation — SwiftUI Tutorials - Apple Developer
    To fine-tune the UI, you'll use Xcode to render previews at different device sizes. Download the project files to begin building this project, and follow the ...Missing: real- | Show results with:real-
  147. [147]
    Apple Developer Documentation
    **Summary of Core Data Integration with SwiftUI:**