Is it Good Idea to Use Swift for Windows / Linux Apps?

I see Swift are primarily used for Apple Device programming... But Swift are now Open source so is it good idea to use Swift for NON Apple OS GUI Apps ? If yes can you guys tell me what GUI Framework should i use (I'm new to programming and still confused about it)

Whether or not it would be a good idea for you to use Swift depends on your needs.

To be up-front about it, Swift on non-Apple platforms obviously doesn't have the same kind of resources behind it as it does on Apple platforms. Things like setting up your development environment may be a bit more involved, and the system libraries are not designed for ease of use from Swift.

It might still be worth it; it all depends what your goal is. You say you're new to programming - do you need to create something by a particular deadline? If so, you may find it easier to get started with something more established, such as Javascript and HTML. If you have more time and flexibility, Swift has lots of advantages and is certainly worth learning.

As for UI frameworks, here are a handful of community projects I found:

5 Likes

I use Swift for cross-platforms applications successfully, i.e. they run on macOS, Linux, and Windows. They are currently command-line only, but I have planned a Windows GUI for one application, I hope The Browser Company will release a nice GUI library for Windows soon. For Linux there e.g. are some wrappers around GTK, see this other forums topic. But I think you should not hope for a good single cross-platform GUI library soon, you certainly will have to do some re-implementation of the GUI for each platform family.

Yes, the Linux and Windows versions of Swift sometimes lag behind the version for Apple platforms (regular expression literals, macros). You might also consider how “secure” the future is for other than the Apple platforms in the long term. From what I heard Apple itself is using Swift on Linux. A while ago some doubts might have been justified for Windows, but I think now the future looks very good even for Windows, even Apple’s Swift team is very positive about Swift on Windows and even help — but you will have to judge for yourself after being part of the community for some time. Programming cross-platforms application will be much nicer once the common standard libraries are finished.

The interesting part about using Swift as a cross-platform language is that I think Swift could be a very nice “successor” to C++, and Swift is better accessible for beginners than Rust, which is often treated as another candidate in this space. And the Swift implementation on Windows is very interesting, because it integrates natively into Windows so to speak, making it a “true native” choice for Windows. And of course you can “naturally” program apps for Apple’s devices.

6 Likes

There's also an effort to support Qt:

1 Like

I'm still Learning about using swift-win32 but I'm really blind to programming since i was started now, there also lacks of Documentation from swift-win32 (either they lack Documentation or i didn't understand it) :(

I couldn't find a good tutorial for properly use swift-win32 sadly

If you mean the GUI package, I would rather wait a bit what The Browser Company will hopefully release soon.

(If you are new to programming, you should rather start with simple command line applications first, using Visual Studio Code with the Swift extension by the Swift server group if you are on Windows. You will have to learn about the language itself and the Swift Package Manager.)

I've also done a bit of research in this area of cross-platform UI wrappers –

although my use case is embedded Linux, so may be different to the OP.

In any case, Swift seems pretty well supported in Linux, not without its issues (occasional compiler bug etc) but I am comfortable enough to bet my project on it. The new cross-platform Foundation should improve things somewhat too.

I'm sorry what is The Browser Company ?

As others have noted, it's possible to use Swift elsewhere, but the support on Apple platforms is greatest.

As a new learner, you might want to try to get the most supportive language and environment possible so you can do more learning than logistics.

Swift on MacOS is by far my favorite. Swift makes many things very easy. If you don't have a mac, getting (a used?) one would likely pay back in time saved and lessons learned significantly.

Just realize that both Swift and Apple are very ambitious. Swift has more features than other languages, and Apple API's and platforms are diverse. You'll have to avoid being distracted by all the shiny toys :slight_smile:

Java could be a good starting language, using IntelliJ or eclipse. Java expressly avoids platform diversity, it's easier to stick with the simpler subset of the language, and the tutorial/teaching ecosystem is highly evolved. (You might learn Swift faster by starting with

As for GUI frameworks, unfortunately the most common is the web in all its roiling complexity (though basic HTML + CSS + javascript is a decent starting point for GUI separation of concerns). To me, GUI's are a kind of siren song: good ones are so attractive, but you can be tossed in the ocean quickly.

Focusing on data and algorithms, and how data is encoded for algorithms, might give you a good feel for the power and joy of programming.

I also have a bunch of command line tools that work on both Mac and Linux. And while Foundation on non-Apple platforms has a lot of problems, you can get pretty far with a bit of hacking.

By now I'm all in with Swift, so I would not consider using another language for the UI ­– no matter which platform. That means you're left with only a few options and many (in particular the declarative ones) still in their infancies. If I were to go for a "classic" UI toolkit, I'd use Qt, it's probably the most mature open source UI toolkit on Linux and Windows these days. That said, https://github.com/Longhanks/qlift unfortunately looks almost abandoned. Perhaps something new using the C++ interoperability would be a better approach.

Yeah, this is what I was talking about.

Since you are new to programming (not just new to Swift - new to programming overall), I would recommend that you start with something more established so you can focus on getting comfortable with programming.

The language doesn't matter so much. Most professionals use (or have used) multiple languages, and when they join a new project, the idea that they would have to use a different programming language is usually not a significant barrier. The language is just a tool that allows developers to express themselves.

On Apple platforms, the developer experience is supported full-time by a large staff of experienced engineers. That leads to an experience where you can just download Xcode, click "New Project > App", and pretty much start coding straight away from there. Swift on other platforms is generally supported by passionate members of the community on a volunteer basis. They do great work, but you should set your expectations appropriately -- it's not entirely as seamless, and you will find occasions where the path forward is a bit unclear or requires you to troubleshoot deeper problems.

Again, I think people should remember - OP is not just new to Swift, but new to programming entirely. The bumpiness of the road means it will likely take longer to get things done if you choose Swift -- you might learn more, but it could also be frustrating. It's nice that people are enthusiastic about Swift and excited about future developments that could help these issues, but for somebody learning programming right now (let's say using Windows), there's a high likelihood that you walk away with a negative impression of Swift or of programming overall, which would be unfortunate. So it's better to make it crystal clear that writing a GUI application for Windows using Swift, today, is not an easy path. It's possible, but I wouldn't choose it as my first ever programming project.

7 Likes

There is another Qt wrapper: GitHub - Longhanks/qlift: Swift library to use Qt (last update is 3 years ago). swift-cross-ui is using qlift is using it as its qtbackend.

Those 2 libraries share the similar archetecture: write some c++ (SwiftQt) or c (qlift) code and wrap it into swift. So, it's like: Swift -> c/c++ -> Qt

You might have a look at Swift/WinRT which was published recently, and the samples, using Win UI 3. Cf. this article.

Qt is cross-platform, but it does not feel completely native e.g. on macOS, is not easy to use, and needs commercial licenses for commercial developers.

I would say for a very good GUI for a cross-platform application one currently should implement the GUI for each platform separately using Apple frameworks / GTK+ / Win UI 3, and the application should be organized accordingly to make this easy. (Maybe there will be something cross-platform for simple GUIs using those frameworks.)

in that case, NAppGui is very close to what you need: Cross-Platform C SDK - NAppGUI it's in C.

Oh nice, I will have a look at it. It uses Win32, so maybe an additional implementation for WinUI 3 would be nice, since this is what is regarded as the current state of the art on Windows according to Microsoft.

It would be interesting to compare it to Swift/WinRT concerning Windows. E.g. from my understanding a native GUI application on Windows needs an according startup hook, so am not sure if just if using this C library gives you the same level of “nativeness” as Swift/WinRT or how this works from Swift. But it might indeed be a good alternative for a wide variety of “simpler” GUI apps as I described above as use case.

Update: The library uses 2D libraries on all platforms to draw the GUI, it does not (!) use any native GUI elements (except the windows of course). :confused: (Sorry, should have looked closer before.)

Hi @sspringer !

Thank you very much for taking the time to review NAppGUI, but your statement is not entirely correct.

NAppGUI uses the native controls to create the GUI. That is, you end up calling CreateWindowEx, NSView or GtkWidget. This is why the appearance is native on all platforms (from Snow Leopard, Ubuntu12 and WindowsXP).

Hello World! - Cross-platform C SDK (nappgui.com)

What may have confused you is the draw2d library. It is an API for cross-platform vector drawing in custom views that makes calls to GDI+, Cairo and Quartz underneath.

2 Likes