Its time for SwiftUI on the web! (WASM, WEBGL)

Hello Apple Community,

With a backend development background, I was always reluctant to do any front end. Especially with my bad experience with html & css, my negative opinion towards UI only got stronger.

When starting a new project at my current company, I was forced to do SwiftUI for iOS. After a few small (I mean really small) hiccups, I really understood the concept and it all became natural.

This positive experience made me want to try other front end frameworks which work for web. I dipped my toes into Jetpack Compose, C# UWP/WPF, Rust with EGUI.

I was really impressed with the performance and possibilities of Rust (EGUI) compiled to WASM. I was especially impressed that you do not have to use any HTML or CSS rather the rendering is completely up to you just like with a desktop application. I was always disappointed of the necessity of html, but with the rise of WASM in the recent years, I really hope there will be amazing alternatives using WASM & WEBGL.

Rust with EGUI is good and all but lets be honest to our self: With the ease of SwiftUI, its obvious why all the best looking applications are on iOS.

Its time for SwiftUI in web.

The advantages for the developers are obvious:

  • Arguably better UI Framework
  • No Html DOM stuff
  • Friendlier for new developers
  • One framework & language for multiple platforms
  • etc ...

But whats in for Apple? Why "waste" resources?

In my opinion the most important thing is: Increased Developer adoption

What is your opinion on this topic?

  • Would you use SwiftUI for web?
  • What are you currently using for web?
  • Do you prefer any other frontend framework over SwiftUI? (not considering the platform)

I strongly agree. I come from a similar background and absolutely love the ease at which I can create beautiful and functional frontends to my iOS applications.

There are projects that tried to create SwiftUI for the web, the most notable of which is IMO TokamakUI. Of course, due to limited funding, this project is still in a primitive stage and not ready for real deployment.

Some of the biggest challenges result from the fact that Swift on the web is not well-developed. Web apps are incredibly small ~300 KB, but just the Swift standard library (the building block of almost all Swift apps) is 3 MB. That's a 10x difference for a hello-world app. Another challenge is breaking up the binary into chunks. Web frameworks have become incredibly good at this, since it's critical for big apps with many pages to scale. The Swift compiler, though, can only create one optimized binary, and I'm not sure if there are any projects that enable this. Lastly, apart from binary-size concerns, we have to remember that web technologies interoperate together, so it's relatively easy to use a random NPM package to implement a niche feature when using web technologies. For a Swift-based framework to compete, it would need to offer extensive support for CSS, fetching and using of JavaScript plugins and seamless importing of HTML components.

Each of those issues requires extensive engineering efforts to realize, but there is some light at the end of the tunnel. Because SwiftUI offers an amazing API and developers practically have to use it on IOS, there is a chance that a smaller binary-size version of TokamakUI could be usable. Thankfully, there is active development on Swift for embedded devices, which also require small binary sizes, so these improvements could be used for Swift on the web. Further, SwiftUI already has a good package ecosystem and extensive support due to development on Apple platforms. If these packages could be ported to TokamakUI, more web developers could start using Swift. If there is enough adoption and subsequent investment, it is possible to resolve the remaining issues of chunking support and integration with web technologies.

I'm a freelancer in iOS development but every now and then I get a request to make small websites for distant relatives or friends or acquaintances of them. I don't like those heavy weight websites that take ages to load (hello WIX) with tons of js and those damned cookies. On the other hand I don't like to make static websites myself in html like in the 90s which look super sparse (though they load very fast).

What I would really like is to make use of my Swift/SwiftUI knowledge in web. Been thinking about some minimal framework or some kind of method to do that. Found some toy projects but I don't want to bring the iOS L&F to the web, I want websites to look like websites but made with SwiftUI. No more CSS and HTML. Compiling SwiftUI to html is the first naive idea that comes to mind. But I lack the broad knowledge of web technologies out there so I find myself unable to devise anything that could nearly rival other sophisticated frameworks.

Its time for SwiftUI on the web! (WASM, WEBGL)
 
 
Q