Host Shared UI on iOS & Desktop
Embed the same composables in each target.
Host Shared UI on iOS & Desktop is a free Kotlin Multiplatform Academy lesson on CoddyKit — lesson 4 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Kotlin Multiplatform Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
Same App, New Hosts
Your shared App composable is ready. Now each platform needs a small entry point that mounts it. The UI code itself never changes.
iOS Wraps Compose in a Controller
On iOS you expose your composable through a UIViewController. The function ComposeUIViewController hands SwiftUI a controller it can present.
fun MainViewController() =
ComposeUIViewController { App() }Call It from SwiftUI
From SwiftUI you wrap that controller in a UIViewControllerRepresentable, so your Kotlin screen becomes an ordinary SwiftUI view.
struct ComposeView: UIViewControllerRepresentable {
func makeUIViewController(context: Context) -> UIViewController {
MainViewControllerKt.MainViewController()
}
}iOS Renders Natively
Under the hood Compose draws using Skia onto an iOS surface, so your shared screen feels native and shares logic with Android seamlessly.
Desktop Uses a Window
On desktop you launch the same App inside an application window. A few lines of Kotlin give you a real desktop program.
fun main() = application {
Window(onCloseRequest = ::exitApplication) {
App()
}
}Desktop Runs on the JVM
The desktop target compiles to the JVM and renders with Skia too, so the same composables you wrote for phones run on macOS, Windows and Linux.
One Composable, Three Hosts
Android uses setContent, iOS uses a view controller, desktop uses a window. All three call the very same shared App function.
Share Even More by Default
Because hosting is the only platform-specific part, almost everything you build lives in commonMain. The shared surface grows large.
Tweak Per-Platform When Needed
You can still branch on platform inside shared code for things like window size or safe areas, keeping a single codebase that adapts nicely.
Test the UI Once
Shared UI means shared UI tests in commonTest, so you verify behavior a single time and trust it on every host you ship to.
Ship Three Apps from One
With hosts wired up, a single Compose codebase powers your Android, iOS and desktop releases, cutting duplicated UI work dramatically. 🚢
Quick Check
How does iOS host a shared composable?
Recap: Host It Everywhere
You mounted the same shared App on iOS through a view controller and on desktop through a window. One Compose codebase, three platforms shipped. 🎯
Frequently asked questions
Is the “Host Shared UI on iOS & Desktop” lesson free?
Yes — the full text of “Host Shared UI on iOS & Desktop” is free to read here on the web, and the Kotlin Multiplatform Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Kotlin Multiplatform Academy course, upgrade to CoddyKit PRO.
What will I learn in “Host Shared UI on iOS & Desktop”?
Embed the same composables in each target. You practise Kotlin Multiplatform Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start Kotlin Multiplatform Academy?
No prior experience is required. Kotlin Multiplatform Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 4 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “Host Shared UI on iOS & Desktop” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this Kotlin Multiplatform Academy lesson?
Yes. Every Kotlin Multiplatform Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- Enable Compose Multiplatform
- Layouts, Modifiers & Theming
- State & Recomposition in Shared UI
- Host Shared UI on iOS & Desktop