Flutter vs Swift

Filip Varda
The Startup
Published in
6 min readFeb 11, 2021

When it comes to mobile apps, Flutter has been gaining popularity since 2017. If you are not familiar with Flutter, it’s an SDK is Google’s UI toolkit for crafting natively compiled applications for mobile, web, and desktop from a single codebase. Let’s pop the big question. Is Flutter better than Swift?

Swift, as a successor of Obj-C, is a modern, fast, and type-safe programming language but it’s still evolving and new features are under development. To use Swift as a programming language, we need to use Apple's development tools such as Xcode and Apple's frameworks which are very well documented.

Flutter is an open-source, multi-platform mobile SDK from Google which can be used to build iOS and Android apps from the same source code. Flutter uses Dart programming language and is also very well documented. Flutter is similar to React Native but with the full support of native features.

App comparison

Let’s say that we have an identical app built in Swift and Flutter. We will compare them on a few comparison points:

  • Onboarding process
  • Build time
  • Reloading
  • Profiling
  • Accessibility
  • App size

Onboarding process

While comparing native iOS app development and iOS app development with Flutter, the onboarding process for native iOS development seems to be less painful and involve less configuration.

It requires just Xcode and a macOS machine to get started. There are many resources and books available online for learning Swift and iOS development. Flutter requires Xcode, plus, additional Flutter tools to get started with the development of iOS apps. As Flutter is still new in the market, there are comparatively fewer development resources available than for native iOS app development.

Build time

Let’s start by building the app in Xcode. We will delete all the derived data and start a clean build in both, Swift and Flutter.

The build time of native iOS apps can be easily measured with Xcode or the xcodebuild command-line tool. In Xcode, we can enable the build timing summary by running the following command.

$ defaults write com.apple.dt.Xcode ShowBuildOperationDuration -bool YES

Once we run the Build command from the Product menu in Xcode, it will show the build time in Xcode. This build took 13.3 seconds and subsequent builds take approximately 3 seconds.

Since we are comparing Flutter and Swift, it would only be fair to try and build an iOS app from our Flutter codebase. Let’s build the app in debug mode using this command:

$ flutter build ios –debug –no-codesign –simulator

As we can see in the first example, it took 33 seconds for the clean build of the Flutter iOS app, and then 10 seconds, 8 seconds, etc for subsequent builds. Taking into account the second example, a clean build of our Flutter app takes approximately 30-45 seconds.

By comparing the build time for the native app and the Flutter app, Flutter apps appear to take a bit longer for clean builds. However, Flutter gets the speed up when building incrementally. The build time for incremental builds in Xcode is superfast.

We can conclude that the build time of Swift in a local machine is faster than that of Dart.

Reloading the app

While developing an iOS app, it’s always required to make code changes and test in the simulator or on devices. This process is also known as reloading the app, which is one of the key features for mobile app development.

In order to compare both apps, let’s imagine a simple button title change. For example, we have a button with the title “Buy now” and we wish to change it to “Get now”. Let’s assume that both apps are already installed and running in the simulator.

So, we made small changes to the app’s code. The time taken by Xcode to build and run the iOS app with the code changes was approximately 7–12 seconds. Flutter, however, has the hot reload feature which means that when we make the changes in the code and reload the app, the changes are reflected in a second. In our case Flutter reloaded the entire app in 3 seconds.

In conclusion, reloading is way faster in Flutter. The native app took approximately 10 seconds, while the Flutter app reloads in approximately 3 seconds.

Profiling

If you are wondering, what is profiling: Profiling is a process of dynamic analysis that measures memory, resources, CPU, and other performance factors of the app. Both Flutter and native tools have great support for profiling the apps.

In Xcode, we can profile an app using instruments. From Xcode, we have the option to profile an app using Product > Profile. This will launch an instruments app where we can analyze the app by different criteria. We can choose any template for profiling, for example, Core data, Network, Leaks, Zombies, etc.

We can select the Time Profiler to measure the CPU threads when we click the button multiple times. Let’s consider the time taken for building the app in profile mode and the CPU performance when the button is clicked 10 times.

At the moment, Xcode does not display the build time for the Profile action, but we can always use a stopwatch. While measuring, the result was about 20 seconds.

In Flutter, we can profile iOS apps using the IDE or from the command line. You can always check flutter documentation and follow the steps necessary to start the app in profile mode. In order to profile apps from the command line, we need to run the following command.

$ flutter build ios –profile –no-codesign

After this, a timer will start and measure the time that is needed for profiling the app. As you can see, this took way more time, 150 seconds.

Profiling is vast and there are various kinds available to benchmark the native and Flutter iOS apps. However, it really depends on the machines and individual apps. Both Xcode and Flutter have cool support for debugging and profiling iOS apps. However, Xcode has a dedicated app and Flutter has a lightweight way to profile apps using the browser.

Accessibility

Accessibility features in the app enhance the user experience of people with disabilities. As iOS application developers, we should also contribute to their lives with little effort by making iOS apps accessible to everyone. Let’s compare how easy it is to add accessibility features in native and Flutter apps.

Apple’s native tools have accessibility baked in the UIKit framework so there is no need to import another framework to enable accessibility support in native apps. There is the Accessibility API provided by Apple, but developers have to provide the correct accessibility information for every UI element in the iOS app using the UIAccessibility protocol. In our app, we can add the accessibility identifiers, labels, and traits using the code. For example:

button.accessibilityIdentifier = "Press Me"

button.accessibilityLabel = "Press Me"

Another way to provide the accessibility data to the user is using StoryBoard and interface builder, which is also very easy to do. By providing this information to the user, they can access these elements using assistive technologies like VoiceOver.

Flutter iOS apps don’t have any mature support to add accessibility; Flutter documentation suggests to audit iOS apps using Xcode’s Accessibility inspector tool. There is an open issue to add accessibility identifiers for testing purposes, but it’s still in progress since 2018.

In terms of accessibility support, Flutters needs an improvement to make betters apps for people with disabilities. There must be something on the Flutter roadmap to enhance the accessibility of Flutter apps.

Application size

Now that we have compared all the aspects of native and Flutter apps, it’s time to compare the size of both apps generated by the native Xcode and Flutter.

For native iOS, you can get the app artifact from the Xcode derived data. The size of the native app is about 25 MB.

The build artifacts of Flutter apps are generated in the build/ios/Debug-iphonesimulator directory of the Flutter project.

The file size of the app generated locally is 52.4 MB. It’s a bit bigger than the native app but the Flutter app has some app icons and other assets embedded.

After comparing the size of the native and the Flutter app, Flutter apps appear to be heavier in size. The Flutter team has acknowledged this fact and you can read the FAQ to know why Flutter apps are big in Size.

Comparison conclusion

Flutter is getting better every day, there is a lot of quality documentation, it gets more popular, etc, but still, it is not just as good as Swift or Java (Android). Flutter apps may be cheaper to develop and easier to maintain, but native apps are built for their specific platform, taking complete benefits of the features of the OS and the software. These apps can directly access the device hardware like microphone, camera, GPS, etc. hence they are quicker in the application, which results in much better UX and performance.

--

--

Filip Varda
The Startup

Freelance Senior iOS Developer. If you have any questions about my articles or iOS development you are welcome to reach out on my email filip.varda.zg@gmail.com