Writing Gnome Apps with Swift

msk-lywenn | 552 points

For another SwiftUI-like wrapper, see also https://github.com/stackotter/swift-cross-ui (used by Adawaita to generate widgets, and mentioned in other comments).

The key premise of this approach is to provide a SwiftUI-like declarative wrapper around Gnome functionality. It's unclear what it adds over swift-cross-ui.

SwiftUI itself has growing pains mainly around being on the right thread for processing/updates and getting data binding right.

Blog entries on swift.org or from Apple tend to be little demos that show the happy path, but when discussing new frameworks (like a Gnome wrapper) or platforms (like the recent embedded), I'd like more demonstration that the authors understand and address key issues and will sustain development. Cross-platform UI frameworks get complicated quickly and have a long tail of issues (cf Flutter, Java/Eclipse, et al) that can be blockers for clients/users. For Swift it doesn't help to have multiple concurrency models and obviously different behaviors on apple platforms and Linux (where UI is not officially tested).

w10-1 | a month ago

Swift is such a delightful language to use, well suited for general application development. It's awesome to see it gaining traction outside of the cocoa ecosystem. If you haven't given it a fair chance yet, I would highly recommend you do!

nickwarren | a month ago

Other things worth checking:

https://github.com/stackotter/swift-cross-ui https://github.com/TokamakUI/Tokamak

I’m also working (slowly) on native Flutter channels:

https://github.com/PADL/FlutterSwift

But this is really targeted at embedded use cases.

lukeh | a month ago

I'm having Deja Vu from about 20 years ago of writing Gnome apps in C# using Mono.

etaioinshrdlu | a month ago

I feel like a cross platform Swift GUI would be a great thing for the world. Swift strikes a great balance between ergonomics and performance, and seems to be the only other mainstream language to have absorbed some of Rust's key features around borrowing references.

zengid | a month ago

I recently wrote a small side project using vala + gtk4.

I tried blueprint, and while I liked the format, I struggled with a lack of documentation on how to do some more advanced things. Gtk's .ui files are ok, but you still end up writing a lot of code to hook everything up.

While I really like vala as a language, I think it'd be great to write all my logic and models in vala, then use this swift library for the UI.

l72 | a month ago

Writing UI code layouts is suboptimal in any language. Delphi had it right - place whatever controls you like in a GUI, set up basic behavior via properties, then just quickly write handlers in code.

treprinum | a month ago

I’ve recently noticed Swift sneakily becoming an interesting option for desktop dev. On top of this example I’d add Arc for macOS and Windows.

imbnwa | a month ago

Something like SwiftUI but open source and targeting GTK4 would be pretty close to my "dream framework" for cross-platform desktop UI.

I will admit, Swift syntax is an acquired taste, but once you're familiar with all of the concepts (and understand that some design decisions were made for Objective-C interoperability), then it's a very usable language. To be frank, the only thing that stops me from using Swift is the fact that Linux support isn't as good as on Apple platforms. But if I am targeting nothing but Apple platforms, then Swift is probably the best choice, just for SwiftUI and SPM alone.

koito17 | a month ago

That looks really nice! A healthy balance of reactive UI, expressiveness, and sanity. I wonder if there's a similar Swift binding for Qt... Ubuntu Touch and KDE could really benefit from that, as QML proved to be a total typing nightmare from my experience, often even slightly worse than regular JS thanks to its quirks...

pona-a | a month ago

Has anyone been able to get this running on Mac. Followed the instructions, but I always get a missing adwaita.h in some shim.h

YmiYugy | a month ago

This is really cool! I love the JSX-like approach to UI and it's a shame it's not so common on desktop. https://github.com/can-lehmann/owlkettle is the only thing I find comparable.

FireInsight | a month ago

You could say "writing Gtk code in X language where I implemented a DSL for this special case is easy!" in any PR piece.

You could do it in Python using contextmanager which packs after adding the widget to HBox to save a line, you could do it in Ruby using do/end blocks, you could do it in C with the help of some pretty macros.

nurettin | a month ago

I wonder where the pulse is with current GTK app development. I've noticed some of the newer core apps are in Rust like the new camera app and the image viewer, also the public transport app railway (not a core app afaik).

tschumacher | a month ago

Is this the only declarative way to write desktop app UI? (Maybe Kaitlin multiplatform, but not sure how that works on Linux). I mean GTK/Qt

tripdout | a month ago

So, the elephant in room, what's the best way/framework today to write desktop apps for linux (no electron)?

throw_m239339 | a month ago

That's neat!

But how is everyone testing their Swift codebases? We've found the story around testing to be... lacking. The [docs](https://developer.apple.com/documentation/xctest) on the subject are pretty bare and don't offer strategies for mocks, stubs, reporting, code coverage, etc.

And good luck if your app uses a Network Extension... those must be tested on a live physical device due to the signing restrictions!

On that note, does anyone know of a good physical device CI service that supports both iOS and macOS devices?

jamilbk | a month ago

I always thought that introducing keys in function parameters was a mistake.

msie | a month ago

How is the 3D story on gtk4 am I still stuck to opengl contexts?

accurrent | a month ago
[deleted]
| a month ago

I don't understand why there are so many negative comments. Writing GUI in C looks like a stone age programming, and people are simply wasting their time to do routine work that can be diminished by using another language. One might use Python, but it is slow and memory-hungry.

Isn't it good that now there is an alternative to C?

codedokode | a month ago

>The primary motivation for this package is to enable the use of Swift when writing GNOME apps, for all the reasons outlined above

The only problem I have with such projects is when they are unmaintained, in various stages of immaturity, and have little adoption (vicious circle).

You find them, they promise exactly what you need, and then you fell into issue after issue in practical use (*).

It would be amazing if there was (perhaps this is or will be) well maintained bindings for Swift/Rust/Go and co for Gnome.

* Yes, it's open source and you can fix some of the issues yourself. Doesn't mean you have the know-how or time to fix all of them, especially when there are lots of things to fix or features missing. Ideally a big community must exist, so that each can just work on or fix a small part and the problem still get lots of fixes/improvements incoming, as opposed to "fully replace the single overworked maintainer yourself".

coldtea | a month ago

Really something we needed.

Swift has such low memory usage, that it's an order of magnitude easier on resources, than those Electron wrappers. At the same time, it gives what you loved about React - expressiveness for UI.

  I wrote a lot of apps in SwiftUI, and it strikes a good balance between type safety and expressiveness, it's cool that we have something similar for GKT/Gnome now.
vi4m | a month ago

Is there a language server for Swift that does not suck?

I believe swift is a good language, however its ecosystem being steered by apple is a massive red flag. It also suffers a bit from being a commercially developed language in that its developers are clearly incentivized to add more features.

eptcyka | a month ago

Flutter desktop app support has been on Ubuntu since 2021, but not sure if that ever got anywhere.

Apocryphon | a month ago

The article doesn't summarise the differences between developing these cross-platform apps vs only targetting Apple and that is the most important information really.

Did I miss it?

QuantumG | a month ago

[flagged]

iidaya00 | a month ago

[flagged]

galina700 | a month ago

I spent 3-years with Swift recently

Makes me want to ask: Why? Why do this?

It is a decent language for 2005. But it has some serious shortcomings (reference counting garbage collector? Really?)

The worst thing IMO is its dreadful support for threads. The "DispatchQueue" seems to be a wrapper around "fork/renice". There is no attempt at memory protection.

But it is full of little niggles that get very irritating in this day and age.

I never used Objective-C so it may be a vast improvement on that.

It is no longer 2005, and we deserve, and we have, better languages.

My time as an Apple developer left me with the overwhelming sensation that Apple hates its developers. So much cool looking stuff that mostly worked...

worik | a month ago

It's an interesting value proposition. But can I take my existing SwiftUI app and have a path towards porting them to Linux and windows? How foreign would they look since Apple's patterns aren't the same.

keyle | a month ago

I had an extremely negative experience creating apps in Swift.

I can't see any logical reason why people would not use Electron/Tauri.

Swift doesn't allow you to have full control of what you want to do.

I built a whole macOS [ fixkey dot ai] app in Swift, and it was a very painful development experience.

Obertr | a month ago