This is an un-opinionated, short article comparing Swift and Electron.js for building Mac OS apps.
These are the two most popular general-purpose ways to create apps for Mac in 2021.
Swift is Apple’s relatively new (2014) programming language.
It slowly replaces Objective-C as the default language for anything on the Apple platform.
Since the first release, developers can use Swift to build native Mac applications way faster than before.
More recently, Apple introduced Swift UI which makes building UIs quite easier with Swift, thanks to a reactive structure than resembles React.
👍 It’s native and recommended by Apple
Your app will be blazing fast, the UI will be as native as it can be to Mac, and you know Apple is fully behind it to support it, even in the future.
If you’ve never used Swift, nor haven’t used a language like Objective-C recently, Swift will take you more time to get familiar with than Electron.
That said, compared to Objective-C, Swift code is cleaner and easier to understand.
You can start Apple’s Mac’s Getting Started Playground to get a better idea of what using Swift to create a Mac app looks like.
👎 The ecosystem is young (and a bit fractured)
You’ll find a lesser variety of options for niche things, and the documentation will generally be rawer.
Get ready to dig into code.
For example, a few weeks ago, I was looking for a pretty and powerful Chart library. The only one that matched the features I required, ended up behind pretty hard to integrate.
The documentation was pretty much non-existent, and I had to go through samples and Stackoverflow threads to understand how to use it and make it look alright. This is the case for a lot of Swift packages.
With Electron and JS, I could have picked between a dozen libraries (like Chart.js, HighCharts, Chartist, …) and saved about 4/5 of the time.
Also, many previous Swift modules are not working with the latest Swift version, and they often don’t support Swift UI directly (in which you have to write a bridge file).
The same way you would create a web app, you can create and distribute desktop applications.
But the true feature of Electron is giving you access to native OS features and bindings, like writing to files.
👍 Fast to get started with
If you’re already familiar with web development, the learning curve will be very low.
If you’re time-constrained or don’t want to go through the Swift learning curve, this might be a good option.
👍 Seamlessly port your app to Windows & Linux
If you decide later to distribute your app to other platforms, it will super easy with Electron.
The only exception is if you use Mac-specific features (which you should then properly fall-back).
👎 It’s not native
Since Electron needs a full Chromium instance to run your app, this implicates some undesired performance hits:
- RAM usage is high by default, even for a “hello world” app
- Bigger distributable size (> 100 MB)
- Animations can run slower
- Electron app can feel a bit clunky
It will also be harder to give your UI the “Mac feel” as you won’t have access to native UI components.
When developing your Electron app, you should be very mindful about performance issues (how you load data, modules, animations) to make sure your app don’t end up feeling clunky.
See some tips for performance here.
- 👍 Recommended way by Apple to build macOS apps
- 👍 Native: top performances
- 👉 Typed language
- 👎 Less flexibility on the UI compared to CSS
- 👎 Young ecosystem compared to JS
- 👍 Almost no learning curve for web devs
- 👍 Seamlessly port your app to Windows & Linux
- 👎 Sub-par performances
- 👎 Won’t feel as “native”
If you’re looking to build a quality app with native performance, need access to platform features, or have previous experience with Objective-C, Swift will probably be the best choice.
Otherwise, if you are a web developer, might port your app to other platforms, or want to save a maximum of time shipping the app, you’ll be happy with Electron.
Plenty of companies (like Spotify and Slack) stuck with Electron even though they could afford to build native apps.
If you think going with Electron is the right choice for you, you might also want to look at some lightweight Electron’s alternative that don’t pack the full Chromium runtime.
In any case, once your app is ready to distribute, you might consider using an analytics solution to track your growth, view your users, detect bugs, and more.
This is what we do at Nucleus.sh and we would love it if you check us out :)