How to: Add Firebase to SwiftUI 2 (2020)

Step by step to make your iOS 12 app support Google Firebase.

Let’s open the Firebase Console first:

We need to open a new project or use an existing one. After entering the project, click “Add Application”. Simply choose iOS as the application platform. Then, download the plist file and put it inside Xcode Project.

Next, we need to add a PodFile in the Xcode Project Folder. You can use terminal to do this step.

$ Pod init

Now, you can see a new file called, “Podfile”.

After that, double click to open PodFile or enter the command.

$ open Podfile

Add the follow line inside target (iOS)

pod ‘Firebase/Analytics’

Note: Do not add it after ‘end’, Firebase only supports iOS/iPadOS at this moment.

Save and run.

$ pod install

After the installation successfully, you will see a new folder and two files.

Double click to open xcworkspace (you don’t need to open xcodeproj file anymore)

Indexing will take some time…

Using Firebase to SwiftUI is very easy. You just need to open xxxApp.swift (Shared) and add

import Firebase

Then, you need to initial the Firebase app by using

init() {
FirebaseApp.configure()
}

inside @main

Try to build on your iPhone or iPad.

Once your app intial successfully, you can see the below message.

Done 👏

You will see the analytics on Firebase, e.g. number of users, etc. The statistic update will take some time, please wait ~24 hours.

Developer, UI/UX Designer and 📽Photographer | Contact: | Website:

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store