SwiftUIWeb: Bringing SwiftUI to the browser with Embedded Swift and WebAssembly

Hi everyone!

I've been working on a project called SwiftUIWeb, and I've just made it open source.

The idea is pretty simple: what if we could take the SwiftUI code we already write for Apple platforms and run it directly in the browser?

SwiftUIWeb lets you build web applications using familiar SwiftUI APIs like View, @State, @Observable, NavigationStack, List, Table, and more.

Under the hood, it uses Embedded Swift compiled to WebAssembly. Swift runs inside a Web Worker, while a lightweight JavaScript layer applies updates to the browser's actual DOM, with CSS handling layout.

So instead of drawing everything onto a canvas, the browser still handles text selection, scrolling, input, accessibility, and other native web behaviors.

Apple's Food Truck, running on the web

To test how far I could push the framework, I took Apple's Food Truck sample application and got it running on iPhone, iPad, and the browser, sharing the same Swift sources.

The video demonstrates all three platforms, including sidebar navigation, sortable tables, charts, maps, and animated layouts.

There were some necessary adaptations, mainly replacing Combine with Observation and providing browser alternatives for APIs like StoreKit and WeatherKit.

But whenever I encountered missing SwiftUI functionality, I tried to implement it in the framework rather than work around it in the application.

Where things stand

The project is still a preview, and there are limitations.

  • It requires the Swift 6.4 toolchain from swift.org and the matching WebAssembly SDK.

  • Some Apple frameworks, including SwiftData and App Intents, don't have browser equivalents.

  • Embedded Swift introduces constraints around reflection, key paths, and certain language features.

  • Initial download sizes are still larger than comparable JavaScript applications. Reducing WebAssembly output is one of my main priorities.

I've documented the architecture, limitations, benchmarks, and examples in the repository.

I'd really appreciate feedback from the Swift community, particularly around Embedded Swift, API compatibility, and anything that could be improved in the compilation approach.

The goal isn't to replace the browser's capabilities, but to make Swift and SwiftUI a practical way to build applications for it.

GitHub: GitHub - Vitorsilveira31/SwiftUIWeb: Build web apps with familiar SwiftUI APIs, powered by Embedded Swift and WebAssembly, and rendered as native browser DOM. · GitHub

Live playground: https://swiftuiweb.vitorsilveira31.workers.dev/

Food Truck example: SwiftUIWeb/Examples/FoodTruck/README.md at main · Vitorsilveira31/SwiftUIWeb · GitHub

Licensed under MPL-2.0. Contributions and feedback are very welcome!

2 Likes

There here have been multiple efforts to unify cross-platform UI development in Swift

Like OpenSwiftUI GitHub - OpenSwiftUIProject/OpenSwiftUI: Open source implementation of Apple's SwiftUI. · GitHub and Skip GitHub - skiptools/skip: Skip enables the creation of native SwiftUI apps for iOS and Android · GitHub

Which essentially provide interoperability layers via code generation or compiler instrumentation.

I'd suggest taking a closer look at OpenSwiftUI.
It already targets embedded ESP32, so adding WASM support through SwiftWASM shouldn't be challenging, considering what you've already implemented in your project.

It worth consolidating related efforts.

1 Like

I just tried playground and this seems to be one of the better web implementations of SwiftUI. Nice job! I'm very happy to see it using embedded wasm.

The API looks to be identical to Apple's SwiftUI. I think ElementaryUI had to diverge from Apple's SwiftUI API to get it to work in embedded Swift. I prefer your approach of keeping it the same.

Do you plan to keep the API close/identical to Apple's SwiftUI?