SwiftWebUI renders SwiftUI views in a browser and keeps a live link to Swift code on the server. The authors describe it as a learning-oriented demo, not for production.
Overview
SwiftWebUI implements much of the SwiftUI API so developers can declare Views that appear in a web browser. Unlike approaches that only translate views to static HTML, it opens a channel between the browser and Swift code running on a server so controls such as buttons, pickers, steppers, lists, and navigation can update interactively.
A small HTTP server using SwiftNIO on port 1337 serves pages. When a browser connects, the framework creates a session, builds a server-side representation of the view tree, renders HTML, and keeps state to diff later updates. User actions in the browser call back into Swift handlers, which can mutate state and push DOM changes as JSON or HTML fragments.
SwiftWebUI is a toy for exploring SwiftUI internals rather than shipping production sites. Apple’s SwiftUI goal of learn once, use anywhere does not mean iOS SwiftUI code will necessarily look identical in the browser.
Running it requires Swift 5.2 or later. macOS 10.15 or newer is one supported host; Linux is supported with OpenCombine for some APIs. A Docker image with a Swift 5.1 snapshot is available for Linux setups. Integration is via Swift Package Manager in an Xcode command-line tool project.
Key features
- SwiftUI Views in the browser
- Interactive server-linked UI
- SwiftNIO HTTP serving
- State and tapAction handlers
- Session-based multi-user serving
- Linux support via OpenCombine
- Docker image for Swift toolchain
- SwiftPM dependency integration
Use cases
- Learning how SwiftUI works
- Prototyping SwiftUI in the browser
- Exploring cross-platform UI patterns
- Demo apps such as Avocado Toast samples