← All blogs
March 1, 2021·ElectronSwift

Swift vs Electron for Mac applications

We take a look at two of the best options for developing a MacOS app in 2021.

Ramón Echeverría
Ramón Echeverría
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

Swift
Swift
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.

👎 Less straightforward than JavaScript

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)

Swift's libraries/package ecosystem is much smaller than JavaScript's.
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).
 

Electron

 
Electron
Electron
 
Electron allows you to create desktop applications from HTML, JavaScript, and CSS.
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.
You will be using Javascript and familiar tools all along. You'll build and design your UI using CSS.
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.

Summary

Swift

  • 👍 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

Electron

  • 👍 Almost no learning curve for web devs
  • 👍 Seamlessly port your app to Windows & Linux
  • 👎 Sub-par performances
  • 👎 Won't feel as "native"

Conclusion

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.
 

 
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 Astrolytics.io and we would love it if you check us out :)

Get the latest posts, right in your inbox

We write about building products using analytics. No spam, ever.

Astrolytics

Understand how well your product is doing today
with Astrolytics

Integrate in minutes and get started with our 30-day free trial.