Protocol

NSViewRepresentable

A view that represents an AppKit view.

Declaration

protocol NSViewRepresentable where Self.Body == Never

Overview

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

For each phase the following methods will be called in order:

// Initialization phase:
makeCoordinator()
makeNSView(context:)
updateNSView(_:context:)

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

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

Topics

Associated Types

associatedtype Coordinator

A type to coordinate with the view.

Required.

associatedtype NSViewType

The type of view to be presented.

Required.

Instance Methods

func makeCoordinator() -> Self.Coordinator

Creates a coordinator instance to coordinate with the NSView.

Required. Default implementation provided.

func makeNSView(context: Self.Context) -> Self.NSViewType

Creates a view instance to be presented.

Required.

func updateNSView(Self.NSViewType, context: Self.Context)

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

Required.

Type Methods

static func dismantleNSView(Self.NSViewType, coordinator: Self.Coordinator)

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

Required. Default implementation provided.

Relationships

Inherits From

See Also

AppKit Hosting

protocol NSViewControllerRepresentable

A view that represents an AppKit view controller.

Beta
struct NSViewControllerRepresentableContext

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

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