Generic Class

NSHostingController

An AppKit view controller that hosts a set of Swift UI views.

Declaration

class NSHostingController<Content> : NSViewController where Content : View

Overview

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 to use as the root view for this view controller; you can change that view later using the rootView property. Use the hosting controller like you would any other view controller, by presenting it or embedding it as a child view controller in your inteface.

Topics

Creating a Hosting Controller Object

init(rootView: Content)

Creates a hosting controller object that wraps the specified SwiftUI view.

init?(coder: NSCoder, rootView: Content)

Creates a hosting controller object from an archive and the specified SwiftUI view.

init(nibName: NSNib.Name?, bundle: Bundle?)

Creates a hosting controller object from the contents of the specified nib file.

init?(coder: NSCoder)

Creates a hosting controller object from the contents of the specified archive.

Getting the Root View

var rootView: Content

The root view of the SwiftUI view hierarchy managed by this view controller.

Configuring the Interface Appearance

func sizeThatFits(in: CGSize) -> CGSize

Calculates and returns the most appropriate size for the current view.

Comparing View Controllers

static func == (NSObject, NSObject) -> Bool

Returns a Boolean value indicating whether two values are equal.

static func != (NSHostingController<Content>, NSHostingController<Content>) -> Bool

Returns a Boolean value indicating whether the two objects are not equivalent.

Getting Hash Information

var hashValue: Int

The hash value.

func hash(into: inout Hasher)

Hashes the essential components of this value by feeding them into the given hasher.

See Also

AppKit Hosting

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.