Building My First App with SwiftUI and Firebase

My experiences after having used both

Archie Edwards
The Startup
7 min readMay 28, 2020

--

Photo by Zan on Unsplash

Last week I released my first app on the App Store called Co-shop

I developed the app in conjuction with the Covid-19 pandemic. The aim was to help people who feel most isolated get their shopping essentials by asking their local community.

The app was really fun to make and I developed it using Apple’s relatively new SwiftUI framework along with Google’s Firebase for the backend.

I’m writing this article to share my initial thoughts on the two as a new comer to mobile app development. If you are reading this a fellow new comer, I recommend both highly as a great starting point for app development.

SwiftUI

For the last 5 years or so, creating a mobile app is something that I have always wanted to do. In particular on iOS mainly because thats what I interract with the most.

However, I previously found that I would embark on a large set of Swift tutorials, come out on the other side having remembered nothing, or more likely lost complete interest. This was mainly my fault as I find starting a project and learning as I go along far more beneficial than following a tutorial. I grew tired of looking at the Interface Builder, fiddling with constraints and Xcode in general felt quite intimidating. Nevertheless, I was no closer to creating an app.

And then came SwiftUI…

When it was announced at last years WWDC conference along with the refreshed Xcode 11, it was clear that iOS development was something I ought to try again. I was impressed initially by the live previews, the new security features but most of all how simple everything looked, it hardly seemed like you needed programming experience.

Here are some of the pros and cons I found whilst trying out SwiftUI for the first time:

Pros

  • Simple and intuitive - As someone who has mostly done backend development to date, I found the declarative approach of SwiftUI to be somewhat familiar and incredibly easy to pick up.
  • Looks great - Creating a UI that looks like an in house Apple application is incredibly easy and takes a few lines of code. I have never thought as myself to be particularly gifted as a UX designer so after a few days playing around I felt pretty confident Co-shop was a project I could bring to life.
  • No more constraints! - I’m sure I can’t be the only one to say that constraints were not fun to deal with. With SwiftUI layout really is a dream to work with and the resuability of views ensures different parts of your app look consistent with one another. Most of the layouts I made were handled with some sort of Stack and Spacer which are very easy to get the hang of.
  • Online resources - Seeing as I decided to leave Swift tutorial classes for this project most of what I created I learnt from online resources. Seeing as it’s a new framework, all resources are up to date which makes a nice change. There are cases where I found my problem to be too niche and had to find a work around but in general solutions were easy to find. If I was to recommend one resource it would be Hacking with Swift. There’s loads of clear, up to date tutorials, and as I m a sucker for anything written in markdown, I welcomed it with open arms and wasn’t disappointed.

Cons

  • iOS13 or later - This is probably the worst part of using SwiftUI because using it does limit your audience. Even though iPhone users do tend to update their phones more often then Android, it’s not ideal but something I’ve accepted.
  • Inconsistencies - During development I found that there were cases where updating @State variables in certain cases were not refreshing the view as expected. At the start, I thought this was my own user error however after researching more it seems to have happened to others, so If it is a bug I’m sure in the next iterations of the framework it will be ironed out.
  • General Xcode annoyance - ..goes without saying however it has improved.

Firebase

I heard about Firebase initially through tutorials I had done prior to SwiftUI coming out and chose it at as my backend solely for it being somewhat familiar to me and for my purpose, completely free. The Getting Started steps are well documented and there are lots of tutorials online to help.

The amount of tools Firebase gives you for free are insane. Having not cast too much thought into what functionality I may need for my backend service when first starting out, I was pleasantly surprised with what is provided.

Here are my thoughts on the features I used:

Authentication

Firebase makes authentication really simple. It handles lots of scenarios out of the box such as:

  • Anonymous sign in
  • Password length constraints
  • Ensuring unique/valid email addresses
  • Adding a display name to users
  • User email verification and password reset emails

There is also lots of documentation to add third party authentication services, in particular Sign In with Apple, which lots of end users appreciate for the security aspects.

The only downfall I found was that Firebase by default does not allow username sign in, and to implement requires a bit of work. You have to store each username in Firestore as a document, with a field containing the mapped UID of the user. Then on sign up, check that the username does not already exist by querying the database. I ended up not implementing it as a feature, mainly because of the extra effort, and the majority of users will want to sign in with a third party service anyway. I do hope to see it as a feature in the future though.

Firestore

With Firebase you get two options for a realtime database, Firebase and Firestore. I chose the latter as it was new and shiny at the time, and seemed like what most people were using.

Firestore stores data in documents and collections rather than a JSON tree structure which felt a bit more intuitive to use. Running queries felt very quick and attaching listeners were really easy to get live updates in my app. Although I didn’t have a lot of data to play with, I liked the idea of how you can partition documents into further sub collections to limit expensive queries.

One thing Firestone does not have, compared to Firebase, is GeoFire. This gives you the capability make geo queries i.e to add a location to documents in the database so you can listen for all nearby users within a given radius. Since my app needed this feature I had to use an open source third party called GeoFirestore to be able to do what I want, which wasn’t ideal due to the lack of support for Swift 5 and it not being as reliable. If I was to do the project again, I would probably choose Firebase for GeoFire and live with the flaws it brings.

Cloud Functions

This was my first experience with Cloud Functions and they really impressed me. To have serverless code executed on the fly is incredibly helpful. In particular I have been able to:

  • Make changes to my app without having to publish an update to the App Store, this meant I could propagate changes instantly to the end user.
  • Tie Authentication triggers with Firestone updates. This can be really helpful to create documents for a new user on sign up.
  • Trigger cloud messaging tasks to send notifications on updates of the database.

Overall it’s allowed me to keep my app incredibly lightweight, focus more on SwiftUI and therefore sped up my development dramatically. Functions have much more to offer and I hope to play with them more in the future.

Cloud Messaging

I left figuring out notifications of my app right till the end of developing the app and it went very smoothly.

Once you have configured your app to listen for remote notifications, the Firebase console provides a good on boarding tutorial and the ability to send test messages to your devices.

You can’t send notifications from your app which makes sense so I dealt with them in cloud functions and it was very simple to implement. You have free rein to customise the title, message, sound and badge number of a notification. The badge number is helpful as it sets the app icon with the red notification circle on the phones home screen.

Overall, I haven’t had a bad experience with Cloud Messaging since enabling it, it’s another great tool in the Firebase arsenal.

Those were some of my initial thoughts after developing my first app on iOS, I’m sure my opinions will change on some things as I continue to develop!

Thanks for reading! 🙂 If you have any questions or want to share your experiences with either, post a comment below!

I also have a newsletter which is completely free where I write about swift related topics. Feel free to sign up using the link below! 👇

--

--

Archie Edwards
The Startup

Hi I’m Archie 🙂 I’m studying comp sci @unibirmingham . Connect with me on Twitter!