Integration with the UIKit and SwiftUI frameworks
Compose Multiplatform is interoperable with both UIKit and SwiftUI frameworks. You can embed Compose Multiplatform within an iOS application as well as embed native iOS components within Compose Multiplatform. This page provides some examples of how you can do this when working with UIKit and SwiftUI frameworks:
Use Compose Multiplatform inside a SwiftUI application
To use Compose Multiplatform inside a SwiftUI application, create a Kotlin function MainViewController()
that returns UIViewController
from UIKit and contains the following Compose Multiplatform code inside:
ComposeUIViewController()
is a library function from Compose Multiplatform that accepts another function passed using the content argument. This function can call other composable functions, for example, Text()
.
Next, you need a structure that represents Compose Multiplatform in SwiftUI. Create the following ComposeView
structure that converts UIViewController
to a SwiftUI view:
Now you can use the ComposeView
structure in other SwiftUI structures.
In the end, your application should look like this:

In addition, you can use this ComposeView
in any SwiftUI view hierarchy and control its size from within SwiftUI code.
If you want to embed Compose Multiplatform into your existing applications, use the ComposeView
structure in any place where SwiftUI is used. For an example, see our sample project.
Use Compose Multiplatform inside a UIKit application
To use Compose Multiplatform inside a UIKit application, add your Compose Multiplatform code to any container view controller. This example uses Compose Multiplatform inside the UITabBarController
class:
With this code, your application should look like this:

Explore the code for the example in this sample project.
Use UIKit inside Compose Multiplatform
To use UIKit elements inside Compose Multiplatform, add the UIKit elements that you want to use to UIKitView from Compose Multiplatform.
You can write this code purely in Kotlin or use Swift as well. In this example, UIKit's MKMapView
component is displayed in Compose Multiplatform. Set the component size by using the Modifier.size(...)
or Modifier.fillMaxSize()
functions from Compose Multiplatform:
With this code, your application should look like this:

Now, let's look at an advanced example. This code wraps UIKit's UITextField
in Compose Multiplatform:
The factory parameter contains the editingChanged()
function and the textField.addTarget()
listener to detect any changes to UITextField
. The editingChanged()
function is annotated with @ObjCAction
so that it can interoperate with Objective-C code. The later action
parameter passes the name of the function that should be called in response to a UIControlEventEditingChanged
event.
The next interesting part is the update
parameter:
This function is called when the observable message state changes its value. The function updates the internal state of the UITextField
so that the user sees the updated value.
Explore the code for this example in this sample project.
Use SwiftUI inside Compose Multiplatform
To use SwiftUI inside Compose Multiplatform, add your Swift code to an intermediate UIView
. Currently, you can't write SwiftUI structures directly in Kotlin. Instead, you have to write it in Swift and pass it to a Kotlin function.
To begin with, add an argument to create ComposeUIViewController
:
Then, pass createUIView
to your Swift code like this:
To create an intermediate UIView
that allows you to interoperate between SwiftUI and UIKit, create the following SwiftUIInUIView
class:
You can then use it in SwiftUI and add it to any Swift code inside:
In the end, your application should look like this:

Explore the code for this example in this sample project.