Framework Integration

Integrate SwiftUI views into existing apps, and embed AppKit, UIKit, and WatchKit views and controllers into SwiftUI view hierarchies.

Overview

Integrate SwiftUI with your app's existing content using:

  • Hosting controllers to add AppKit, UIKit, or WatchKit views and view controllers to your SwiftUI interfaces. A hosting controller wraps the designated view or view controller and facilitates communication between the wrapped object and your SwiftUI views.

  • Representable objects to add SwiftUI views into your existing AppKit, UIKit, or WatchKit interfaces. A representable object wraps a set of SwiftUI views in a form that you can then add to your storyboard-based app.

Topics

Essentials

Interfacing with UIKit

SwiftUI works seamlessly with the existing UI frameworks on all Apple platforms. For example, you can place UIKit views and view controllers inside SwiftUI views, and vice versa.

Creating a watchOS App

This tutorial gives you a chance to apply much of what you’ve already learned about SwiftUI, and — with little effort — migrate the Landmarks app to watchOS.

AppKit Hosting

class NSHostingController

An AppKit view controller that hosts a set of SwiftUI views.

class NSHostingView

An AppKit view that hosts a SwiftUI view hierarchy.

protocol NSViewControllerRepresentable

A wrapper that you use to integrate an AppKit view controller into your SwiftUI interface.

protocol NSViewRepresentable

A wrapper that you use to integrate an AppKit view into your SwiftUI view hierarchy.

UIKit Hosting

class UIHostingController

A UIKit view controller that manages a SwiftUI view hierarchy.

protocol UIViewControllerRepresentable

A view that represents a UIKit view controller.

protocol UIViewRepresentable

A wrapper for a UIKit view that you use to integrate that view into your SwiftUI view hierarchy.

WatchKit Hosting

class WKHostingController

A WatchKit interface controller that hosts a SwiftUI view hierarchy.

class WKUserNotificationHostingController

A WatchKit user notification interface controller that hosts a SwiftUI view hierarchy.

protocol WKInterfaceObjectRepresentable

A view that represents a WatchKit interface object.

enum DigitalCrownRotationalSensitivity

The amount of Digital Crown rotation needed to move between two integer numbers.

Deprecated

Deprecated Symbols

Review unsupported symbols and their replacements.

See Also

User Interface

Views and Controls

Present your content onscreen and handle user interactions.

View Layout and Presentation

Combine views in stacks, generate groups and lists of views dynamically, and define view presentations and hierarchy.

Drawing and Animation

Enhance your views with colors, shapes, and shadows, and customize animated transitions between view states.