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.
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!