How to Add Firebase to your iOS Project in 10 mins

Firebase iOS

Adding Firebase to your iOS App in the first step before start using Firebase products such as Authentication, Database, Cloud Functions etc.

In this Firebase iOS tutorial, I will be walking you through how to connect Firebase to your iOS app using Swift Language with STEP by STEP instructions.

Create a New Xcode Project

Go ahead and open up Xcode and choose File → New → Project.

choose-single-view-app-xcode-ios

Then, Choose a Single View Application from the template pop-up window and click next.

choose-option-for-new-ios-project

Give it a project name of your choice and mine is FirebaseiOSDemo and make sure that the Language is set to Swift and Click Next,

Xcode will ask where to save the project and you can choose any location from your computer and Click Create.

Done!

Next step would be to create a Firebase Project.

Create a Firebase Project

Go to Firebase and log in with your Google account if you have it already, otherwise create a gmail account.

Once you’ve logged in, Create a new project by clicking + Add Project button from the Firebase Console

If you have a few project created already, you can see them along with + Add Project button on your Firebase Console page.

Firebase will bring a pop-up window when you hit + Add Project button.

firebase-add-a-project

Make sure to add a Project Name and select the checkbox of terms and click Create Project.

It will take a few seconds to finish creating a new project. Once it’s done, click Continue to the Project Console.

firebase-console-ios-icon

Click the iOS icon that will be on the middle of the page.

If you do not see the iOS icon for some reason, you can go to the Firebase dashboard → Project Overview (at the top left) → click the gear icon → click Project Settings

If you scroll down, at the bottom, you can see the iOS icon. 

Once you have clicked the iOS icon, you will be directed to the Add Firebase to Your iOS App page which has five steps to complete.

The first one is Register App.

Register App

To set the iOS Bundle ID input field, hop over to your Xcode project and select root of the project folder from the Project Navigator panel at the top left.

bundle-identifier-xcode

Then, choose General  → IdentityBundle Identifier. Copy it.

Head back over to Firebase and paste it in there. In my case com.softauthor.FirebaseiOSDemo.

App nickname and App Store ID input fields are optional, so I am going to leave them blank.

Click Register App.

Download Config File

At this stage, Firebase created .plist file. Go ahead download the Download GoogleService-Info.plist  file to your computer. In my case, it will be downloaded into my Downloads folder.

Move the .plist file that you’ve downloaded from the downloads folder to Xcode Project Navigator at the root level.

When you let go, you will get a pop-up window and make sure to copy items if needed and Add to targets are checked.

Then, click Finish.

At this stage, you can see the .plist file added to the project navigator.

add-firebase-plist-file-to-project-navigator

Make sure that the GoogleService-Info.plist file added the sibling to info.plist file.

Head back to the Firebase Console, to your iOS page, and click next, which will bring you to the second step, Add FirebaseSDK.

Add Firebase SDK

To do that, you need to install CocoaPods if you haven’t already. Open up your Terminal → Run sudo gem install cocoapods command to install CocoaPods.

CocoaPods is a dependency manager for Swift and Objective-C which will help you to install third-party packages like Firebase to your Xcode project.

Once you have cocoapods installed, the next step would be to create a Podfile.

To create that, open up a terminal window and navigate to the location of your Xcode project folder.

pod init
xcode-project-podfile

if you navigate to your Xcode project folder in Finder, you will be able to see the new file called PodFile added to the project. 

Next, add Firebase Pod to the PodFile.

To add that, open up the PodFile and add the code below under # Pods for FirebaseiOSDemo and save the file.

pod 'Firebase/Core'
pod-file-add-firebase-pod

Finally, go to Terminal and locate the Xcode project folder and run:

pod install

This will take a few seconds to download Firebase dependencies and integrate it into your Xcode project.

Once it’s done, you can see a few files added to the project when looking at the project folder in Finder.

pod-install-xcwordspace

From now onwards, you will need to use .xcworkspace to open up the project instead of using .xcodeproj.

Go ahead and close the Xcode project if you haven’t already done so, and open up .xcworkspace file to launch the project.

As you can see, on the project navigator, there are two sections: one is an actual project file and the other one is pod files.

pod-files

The next step is to add the initialization code from Firebase to Xcode.

Add Initialization Code

Open up FirebaseiOSDemo folder from the project navigator → choose AppDelegate.swift file in which I will be adding two lines of code.

One is at the top:

import Firebase

Another one is inside didFinishLaunchingWithOptions() method but before the return true line in the AppDelegate.file.

FirebaseApp.configure()

Run Your App to Verify the Installation

Run your Xcode project by clicking the ► icon at the top or Cmd + R.

Then, go to Firebase and wait for a few seconds and you can see it! Congratulations, you’ve successfully added Firebase to your app!

At this stage, Firebase has been added to your Xcode project. 

There you have it 🙂

What are the Firebase Products that you intend to use in your iOS App? Mine is Firebase Authentication for User Authentication, Firestore for Database and Cloud Functions for Back-end code.

NEXT → iOS Facebook Login Using FirebaseUI in 20 MINS