Protocol

NSViewControllerRepresentable

A view that represents an AppKit view controller.

Declaration

protocol NSViewControllerRepresentable where Self.Body == Never

Overview

In the lifetime of a representable view, SwiftUI initializes a NSViewController and a Coordinator, updates them (often repeatedly), and deinitializes them.

For each phase, SwiftUI calls the following methods in order:

// Initialization phase:
makeCoordinator()
makeNSViewController(context:)
updateNSViewController(_:context:)

// Update phase:
updateNSViewController(_:context:)

// Deinitialization phase:
dismantleNSViewController(_:coordinator:)

Topics

Associated Types

associatedtype Coordinator

A type to coordinate with the view controller.

Required.

associatedtype NSViewControllerType

The type of view controller to be presented.

Required.

Instance Methods

func makeCoordinator() -> Self.Coordinator

Creates a coordinator instance to work with the view controller.

Required. Default implementation provided.

func makeNSViewController(context: Self.Context) -> Self.NSViewControllerType

Creates a view controller instance to be presented.

Required.

func updateNSViewController(Self.NSViewControllerType, context: Self.Context)

Updates the presented view controller (and coordinator) to the latest configuration.

Required.

Type Methods

static func dismantleNSViewController(Self.NSViewControllerType, coordinator: Self.Coordinator)

Cleans up the presented view controller (and coordinator) in anticipation of their removal.

Required. Default implementation provided.

Relationships

Inherits From

See Also

AppKit Hosting

struct NSViewControllerRepresentableContext

The context in which updates to an associated AppKit view controller take place.

Beta
protocol NSViewRepresentable

A view that represents an AppKit view.

Beta
struct NSViewRepresentableContext

The context in which updates to an associated AppKit view take place.

Beta
class NSHostingView

An AppKit view that hosts a SwiftUI view hierarchy.

Beta

Beta Software

This documentation contains preliminary information about an API or technology in development. This information is subject to change, and software implemented according to this documentation should be tested with final operating system software.

Learn more about using Apple's beta software