---
title: NSViewControllerRepresentable
framework: swiftui
role: symbol
role_heading: Protocol
path: swiftui/nsviewcontrollerrepresentable
---

# NSViewControllerRepresentable

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

## Declaration

```swift
@MainActor @preconcurrency protocol NSViewControllerRepresentable : View where Self.Body == Never
```

## Overview

Overview Use an NSViewControllerRepresentable instance to create and manage an NSViewController object in your SwiftUI interface. Adopt this protocol in one of your app’s custom instances, and use its methods to create, update, and tear down your view controller. The creation and update processes parallel the behavior of SwiftUI views, and you use them to configure your view controller with your app’s current state information. Use the teardown process to remove your view controller cleanly from your SwiftUI. For example, you might use the teardown process to notify other objects that the view controller is disappearing. To add your view controller into your SwiftUI interface, create your NSViewControllerRepresentable instance and add it to your SwiftUI interface. The system calls the methods of your custom instance at appropriate times. The system doesn’t automatically communicate changes occurring within your view controller to other parts of your SwiftUI interface. When you want your view controller to coordinate with other SwiftUI views, you must provide a Coordinator instance to facilitate those interactions. For example, you use a coordinator to forward target-action and delegate messages from your view controller to any SwiftUI views. warning: SwiftUI fully controls the layout of the AppKit view controller’s view using the view’s frame and bounds properties. Don’t directly set these layout-related properties on the view managed by an NSViewControllerRepresentable instance from your own code because that conflicts with SwiftUI and results in undefined behavior.

## Topics

### Creating and updating the view controller

- [makeNSViewController(context:)](swiftui/nsviewcontrollerrepresentable/makensviewcontroller(context:).md)
- [updateNSViewController(_:context:)](swiftui/nsviewcontrollerrepresentable/updatensviewcontroller(_:context:).md)
- [NSViewControllerRepresentable.Context](swiftui/nsviewcontrollerrepresentable/context.md)
- [NSViewControllerType](swiftui/nsviewcontrollerrepresentable/nsviewcontrollertype.md)

### Specifying a size

- [sizeThatFits(_:nsViewController:context:)](swiftui/nsviewcontrollerrepresentable/sizethatfits(_:nsviewcontroller:context:).md)

### Cleaning up the view controller

- [dismantleNSViewController(_:coordinator:)](swiftui/nsviewcontrollerrepresentable/dismantlensviewcontroller(_:coordinator:).md)

### Providing a custom coordinator object

- [makeCoordinator()](swiftui/nsviewcontrollerrepresentable/makecoordinator().md)
- [Coordinator](swiftui/nsviewcontrollerrepresentable/coordinator.md)

### Performing layout

- [NSViewControllerRepresentable.LayoutOptions](swiftui/nsviewcontrollerrepresentable/layoutoptions.md)

## Relationships

### Inherits From

- [View](swiftui/view.md)

## See Also

### Adding AppKit views to SwiftUI view hierarchies

- [NSViewRepresentable](swiftui/nsviewrepresentable.md)
- [NSViewRepresentableContext](swiftui/nsviewrepresentablecontext.md)
- [NSViewControllerRepresentableContext](swiftui/nsviewcontrollerrepresentablecontext.md)
