Adding Firebase to iOS Project — The Lazy Way
3 steps to add Firebase to your SwiftUI iOS app
If you are not already using CocoaPods in your project, you should start by installing it using this command:
sudo gem install cocoapods
Step 1: Add Podfile and install pods
Create a new Podfile in your project directory, or update an existing one. Your file should look like this:
platform :ios, '14.0'target 'MyCoolApp' douse_frameworks! # Required for Swiftpod 'Firebase/Auth'pod 'Firebase/Firestore'pod 'FirebaseFirestoreSwift'# ... Any other pods you needend
In this example, I am using the Firebase Authentication and Firestore pods, but you should use the pods for the Firebase products relevant to your project.
Now, install pods:
pod install --repo-update
Open the .xcworkspace
(not .xcodeproj
) and build your project.
Step 2: Create the AppDelegate file
Create an AppDelegate.swift
file, and include the following code:
Now, add the following line to your App.swift
file:
@UIApplicationDelegateAdaptor(AppDelegate.self) var appDelegate
Your file should look like that:
Step 3: Add the iOS app to the Firebase project
Go to the Firebase console, and create a new project, or select an existing one. On the top of the project main page, click the iOS icon
Follow the instructions to add the app to your Firebase project and download the GoogleService-Info.plist
config file. Add the downloaded file to your project. Also, remember to add it to your .gitignore
file.
You will need the App bundle ID which you can get in Xcode from the .xcodeproj
file under General → Identity → Bundle Identifier.
That is all you need to do to add Firebase to your Swift-based iOS app. In future posts, I will summarize how to integrate Firebase authentication and Firestore into your iOS app using SwiftUI.