3 ms·
Unrelated question. Anyone know if it would be difficult to write a SwiftUI “compiler” to non-Mac architectures, including wasm? (I’m not a ui developer). I mea
by meling 3y ago
Unrelated question. Anyone know if it would be difficult to write a SwiftUI “compiler” to non-Mac architectures, including wasm? (I’m not a ui developer). I mean, I realize it is probably non-trivial, like most cross-platform ui, but I have been imagining that Apple would do this since they released it, so that their webapps could be written in SwiftUI instead of whatever they are doing now…
- mdasen 3y agoYes, it would be difficult. Certainly not impossible, but difficult. Microsoft has their MAUI project (Multi-platform App UI). It lets you write programs in C# and compile for Windows, macOS, Android, and iOS. AvaloniaUI and Uno Platform are other C# options. Flutter exists for Dart. Compose Multiplatform exists for Kotlin. React Native exists. All that said, they all have drawbacks/issues. Flutter means ignoring the platform and just drawing things using Skia so Flutter apps feel like Flutter apps, not platform specific apps. Compose Multiplatform is only an alpha for iOS and it's also just drawing on a canvas (though you can break out of that and program specific stuff in iOS's UIKit). Avalonia is Skia and from what I've heard the iOS/Android support is poor compared to desktop OSs. Uno is mostly Skia with some platform-specific widgets, but their desktop support is poor compared to their mobile and WASM support. MAUI is the only one that's really targeting native widgets on macOS, Windows, iOS, and Android. It seems like it's been a bit of a hard journey for Microsoft there, but it seems to be getting pretty decent in the latest betas (especially if you're using things like the CommunityToolkit MVVM and Markup extensions). So, it's hard. It's taken many great companies many years to create ok cross platform toolkits. None are really amazing. I think another thing holding stuff back is WASM. WASM will be getting a lot better, but it's not amazing for UI stuff right now because it means overhead communicating between WASM and JS (and a lot of copying). WASM also isn't great for garbage collected languages at the moment since the language has to ship its garbage collector. This will be changing in the future as WASM gets GC support. Swift's reference counts don't require the same overhead so it might not have that pitfall, but WASM is still usually for things that require lots of calculation compared to the UI work at the moment. I don't know how much code reuse there would be between SwiftUI and the web if they did create such a compiler. Maybe there's value in using SwiftUI instead of React or whatever on the web. I don't really know. I think Apple is unlikely to be the company that really pursues a cross-platform toolkit. They want people in their ecosystem and they know that a lot of developers target iOS first. I guess it really depends on the value Apple would get out of it. Companies have spent a lot of time trying to make cross-platform UI kits over decades and there have been a lot of failures (or successes that don't really seem like successes given a lack of popular adoption). PhoneGap was an early iOS/Android one. RubyMotion has been around since 2012. Java was probably the original "write once, run anywhere with a GUI" language. Tcl/Tk has been around for ages. Qt has been around for a long time. It seems like an area where companies pour money and don't get amazing results. I'm not arguing that the results aren't worth it sometimes to have a single codebase. However, I haven't seen one of these toolkits take over the world despite the clear benefits of writing code once. That doesn't mean that the perfect thing can't be done, but it does make it seem like the difficulty is up there to make something really great. For Apple, it's probably just not worth it. Most of their web stuff is different enough to what they'd be running on devices that they might not get a ton of value out of it for the difficulty involved. Plus, Apple isn't really looking to support Android, Windows, or Linux.
- meling 3y agoWow! Thanks for that very nice write up!
- saagarjha 3y agoHard, but doable. I don’t see Apple doing it anytime soon because it doesn’t really gain them anything but here’s a third party demo: https://github.com/swiftwebui/SwiftWebUI https://github.com/swiftwebui/SwiftWebUI
- meling 3y agoAh, thanks. I now recall that I’ve seen this project before…
- WorldMaker 3y agoOne of the rumors for Apple's increased visible attempts to, among other things, rewrite Foundation libraries themselves in Swift is to better unify their own internal cross-platform efforts (because they get to maintain Apple TV and Music apps on nearly every platform, if no other reason). I don't know how much Apple is incentivized to make any steps they take towards SwiftUI cross-platform support available to third party developers, but it is an interesting rumor to watch.