<!--
{
  "availability" : [
    "iOS: 13.0.0 -",
    "iPadOS: 13.0.0 -",
    "macCatalyst: 13.0.0 -",
    "macOS: -",
    "tvOS: 13.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: -"
  ],
  "documentType" : "symbol",
  "framework" : "SwiftUI",
  "identifier" : "/documentation/SwiftUI/UIViewControllerRepresentable",
  "metadataVersion" : "0.1.0",
  "role" : "Protocol",
  "symbol" : {
    "kind" : "Protocol",
    "modules" : [
      "SwiftUI"
    ],
    "preciseIdentifier" : "s:7SwiftUI29UIViewControllerRepresentableP"
  },
  "title" : "UIViewControllerRepresentable"
}
-->

# UIViewControllerRepresentable

A view that represents a UIKit view controller.

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

## Overview

Use a [`UIViewControllerRepresentable`](/documentation/SwiftUI/UIViewControllerRepresentable) instance to create and manage a
<doc://com.apple.documentation/documentation/UIKit/UIViewController> 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
[`UIViewControllerRepresentable`](/documentation/SwiftUI/UIViewControllerRepresentable) 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`](/documentation/SwiftUI/NSViewControllerRepresentable/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 UIKit view controller’s
> view using the view’s
> <doc://com.apple.documentation/documentation/UIKit/UIView/center>,
> <doc://com.apple.documentation/documentation/UIKit/UIView/bounds>,
> <doc://com.apple.documentation/documentation/UIKit/UIView/frame>, and
> <doc://com.apple.documentation/documentation/UIKit/UIView/transform>
> properties. Don’t directly set these layout-related properties on the view
> managed by a `UIViewControllerRepresentable` instance from your own
> code because that conflicts with SwiftUI and results in undefined behavior.

## Topics

### Creating and updating the view controller

[`makeUIViewController(context:)`](/documentation/SwiftUI/UIViewControllerRepresentable/makeUIViewController(context:))

Creates the view controller object and configures its initial state.

[`updateUIViewController(_:context:)`](/documentation/SwiftUI/UIViewControllerRepresentable/updateUIViewController(_:context:))

Updates the state of the specified view controller with new information
from SwiftUI.

[`UIViewControllerRepresentable.Context`](/documentation/SwiftUI/UIViewControllerRepresentable/Context)

[`UIViewControllerType`](/documentation/SwiftUI/UIViewControllerRepresentable/UIViewControllerType)

The type of view controller to present.

### Specifying a size

[`sizeThatFits(_:uiViewController:context:)`](/documentation/SwiftUI/UIViewControllerRepresentable/sizeThatFits(_:uiViewController:context:))

Given a proposed size, returns the preferred size of the composite view.

### Cleaning up the view controller

[`dismantleUIViewController(_:coordinator:)`](/documentation/SwiftUI/UIViewControllerRepresentable/dismantleUIViewController(_:coordinator:))

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

### Providing a custom coordinator object

[`makeCoordinator()`](/documentation/SwiftUI/UIViewControllerRepresentable/makeCoordinator())

Creates the custom instance that you use to communicate changes from
your view controller to other parts of your SwiftUI interface.

[`Coordinator`](/documentation/SwiftUI/UIViewControllerRepresentable/Coordinator)

A type to coordinate with the view controller.

### Performing layout

[`UIViewControllerRepresentable.LayoutOptions`](/documentation/SwiftUI/UIViewControllerRepresentable/LayoutOptions)



---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)
