SwiftUI for non-Apple platforms (like Android, Web, Windows)

I know that SwiftUI isn't part of the Open Source Swift Project and therefore can't be really influenced by the Swift community, but during the related WWDC sessions I couldn't stop thinking that the new declarative and abstract way of specifying UI is the perfect way to enable Swift applications on non-Apple platforms like the Web, Windows and Linux. While the current goal of Apple is to make it possible to write code once and deploy on all Apple platforms (or "learn once and apply anywhere" to use their words), why stop there? Declaring Text, Button, VStack etc. applies to all kinds of UIs and therefore could be also implemented for Windows, Android or even the Web.

Regarding how this could be tackled, I have no idea. The best way would be if Apple would be behind this itself (although I'm not sure how they could profit from it). But if the goal to make Swift a general purpose language is taken seriously, I think adding support for other platforms within SwiftUI would be a game-changer regarding Swift adoption. Just imagine how great it would be if the code you have written for your iOS/macOS apps could be mostly reused both on the Web and also on Windows and Android devices. Swift is already one of the most popular languages amongst developers and it could beat out all the other languages easily in my opinion if it just would be more useful on more platforms.

To be a little more realistic, I think the most pragmatic way how this could come to life is if Apple open sourced just the basic algorithms and the "API" of SwiftUI and the discussion around it so other platforms could adopt changes early on. Then open source projects (like Vapor for the Web) or even companies like Microsoft (for Windows) and Canonical (for Ubuntu) could do the heavy lifting of actually implementing the UI for their platforms. And Apple could provide some intermediate layer which contains the algorithms to infer the final UI representation from all the declarative code, including the logic to update the UI based on data which they should have already implemented anyways.

I know all this sounds like too good to ever happen, but sometimes one has to dream big and SwiftUI itself is proof that some dreams actually do come true. What do you guys think? Did anyone else had the same thoughts? Maybe it's even their long-term plan, who knows?

66 Likes

I could imagine that allowing SwiftUI to be ported to other systems was imagined by Apple from the start.

Naming it SwiftUI and reusing the Swift logo just gives the connotation that it belongs to Swift - the open source project.

Would love to be able to use Swift and SwiftUI for cross platform development instead of Googles Dart/Flutter etc.

Cheers

13 Likes

I agree that this would be absolutely fantastic and I really hope it's in the future, but I'm going to do my best to not get my hopes up. Keep in mind that Swift itself doesn't even work on Windows (or even the web).
I think the hardest question is "Why would Apple do this?". Well, I'm going to go out on a limb and guess that Apple isn't a fan of Electron apps being the main way modern apps get added to MacOS and iOS. People are making web apps first, and porting them to different platforms because the technology allows easy porting. If SwiftUI became a cross-platform solution, it would allow developers to make apps for Apple platforms first, and bridge the app to more places. It would take a lot of wind out of the selling point of web apps - currently the best way to "write once, run anywhere"
That said, I'm probably just justifying it because I want it. Apple seems to enjoy pretending they have the only platforms. It would definitely be "un-Apple-like", but in the best way!
One more thing: SwiftUI is currently close-sourced, but it's using swift features that are included in 5.1. I would love to see proof of concepts making a swiftUI-like framework that works on Apple platforms + Linux, Android, or the web (whichever is easier - I honestly don't know)

5 Likes

It would be awesome if Apple made the SwiftUI fronted open source, and you could connect the backend you want (UIKit, AppKit, HTML+CSS+JS, Windows Forms...).

In any case, the community, or other companies can also reimplement it in a source-compatible way. There are already some very interesting proof of concepts in the wild, for example this project generates HTML from a SwiftUI View.

14 Likes

I agree, it is now or never, the chance for Swift to finally be recognized by all as a true crossplatform language, that's the perfect project to demonstrate this idea but if google starts going crossplatform with Compose before Apple, then it'll be impossible to catch up

We should all then file radars to signal that we all want SwiftUI and Combine (like GCD) to be part of the open source project.

Having Combine as an open source project, it would enable the SwiftNIO project to adopt it to other platforms rather them just on Apple platforms.

Not only that, we could call both projects home in the forums as well.


Linked this post, feel free to retweet it: https://twitter.com/DevAndArtist/status/1137366977947873281

12 Likes

Good idea! Done: “Apple should open source the frontend of SwiftUI (FB6135533)”

6 Likes

As many other devs around the world, this was the first thought I had after the presentation of the platform.

While the use of the "Swift" word seems influenced just by marketing guys at Apple I would also strongly believe it's also a way to embrace the same spirit of collaboration and growth behind the Swift project.

Along with the hard work of Vapor, Kitura and all the web team to bring Swift on server side we really need of another big step forward to make Swift recognizable outside the Apple ecosystem.
This my 2 cents about the topic and my first post here after months of lurking. Go Swift!

5 Likes

Yup, same thought here! I've been mentioning it on twitter but my voice isn't loud enough & there seems to be too much love for Apple to talk about anything negative right now. Agree we should keep signalling this and hope for the best!

2 Likes

The high level declarative nature of SwiftUI should make it possible to reimplement the front end on any platform with just Combine & function builders.

Making the back ends work nice on any particular platform would still take effort, but at least it would have the benefit of not needing to emulate lower level Apple APIs, which is the big reason why Microsoft’s UIKit clone and GNUStep can’t keep up to date with Apple.

It’s also high level enough to that most of the controls and views can be backed by the actual platform native controls instead needing to reimplement them like QT does. This seems like a nice selling point.

3 Likes

It's not a given that Combine will become an open-source framework and ported to other systems. Combine.framework is still an Apple-specific component, considered part of the Apple OS ecosystem.

I never said it would be, but asking for Apple to open source Combine seems a lot more likely to succeed than asking for SwiftUI to be open sourced, and if that happens then writing a SwiftUI compatible framework becomes possible.

3 Likes

True, but apple did give us Grand Central Dispatch so we can bring it to other platforms, so why not package this up with a new reactive framework to share the same reactive paradigm across most if not all platforms supporting Swift?! :slight_smile:

Even if not on Windows and Linux, SwiftUI as a Frontend would close the gap. Full-stack development in Xcode is such a great dream :smile:

2 Likes

You can add Combine to Server side and Serverless environment and the world becomes reactive.

Combine at the moment appears to be the buggiest part of the Beta 1 new APIs, I hope they doesn't have announced it as open source just for that reason... Hopefully it will be released in the future, if the community will embrace it...

Just a question here:
If combine will be released as Open Source, is possible that it will be available also for previous versions of iOS?

The reason Combine is only available in iOS 13 is that it‘s compiled binary is only available on iOS 13. If it was open source, you could just compile it yourself and therefore include the compiled binary to your application directly, at least that‘s how I understand it.

So:
Yes, if it was open source it would probably work on any platform that runs Swift 5.1.

1 Like

That's a possibility but not a requirement and unlikely to happen, but that's only my guess. If Apple was to open source that library, it will still remain a core part of the latest OS's which likely would mean that the API itself is still OS locked in the open source variant of the project just like latest Swift stdlib API's are.

+1 for the idea. The cross platform frameworks are getting good and it’s getting harder to justify writing apps only for a single platform.
I already had a plan to learn Flutter but writing cross platform apps in Swift is a dream. That could also be the killer project that may bring much popularity to Swift outside of iOS.

12 Likes