What is Firebase SDK for Swift?
Firebase SDK (Software Development Kit) for the Swift language is a powerful set of tools from Google that provides iOS app developers with a ready-made infrastructure for building a backend (Backend-as-a-Service, BaaS). Instead of writing server code from scratch, you get ready-made cloud services: a database, authentication, analytics, cloud storage, push notifications, and much more.
Firebase SDK for Swift allows you to:
- Store data in real time (Firestore and Realtime Database)
- Authenticate users (email/password, Google, Apple, Facebook, etc.)
- Upload files to cloud storage (Cloud Storage)
- Send push notifications (Cloud Messaging)
- Collect analytics (Google Analytics for Firebase)
- Set up A/B testing (Remote Config)
- Catch errors (Crashlytics)
The library is distributed via Swift Package Manager (SPM) or CocoaPods. It is the official SDK from Google, which is maintained and updated.
Installing Firebase SDK for Swift
Option 1: Swift Package Manager (SPM) — Recommended Method
- Open your project in Xcode
- Go to File → Add Packages...
- Paste the repository URL:
https://github.com/firebase/firebase-ios-sdk.git - Select the desired version (latest stable is recommended)
- Select the required modules (e.g.,
FirebaseFirestore,FirebaseAuth) - Click Add Package
Option 2: CocoaPods
If you use CocoaPods, add to your Podfile:
platform :ios, '13.0'use_frameworks!
target 'YourAppName' do pod 'FirebaseFirestore' pod 'FirebaseAuth' pod 'FirebaseStorage' pod 'FirebaseAnalytics' pod 'FirebaseMessaging'endThen run in the terminal:
pod installSetting up the project in the Firebase console
- Go to console.firebase.google.com
- Create a new project or select an existing one
- Add an iOS app
- Download the
GoogleService-Info.plistfile - Drag it into the root of your Xcode project
Quick Start with Code Example
After installation and setup, initialize Firebase in AppDelegate.swift:
import UIKitimport FirebaseCore
@mainclass AppDelegate: UIResponder, UIApplicationDelegate { func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { FirebaseApp.configure() return true }}Now you can use Firebase. A simple example of writing and reading data from Firestore:
import FirebaseFirestore
class ViewController: UIViewController { let db = Firestore.firestore()
override func viewDidLoad() { super.viewDidLoad() addUser() readUsers() }
func addUser() { db.collection("users").addDocument(data: [ "name": "Ivan Petrov", "age": 25, "email": "ivan@example.com" ]) { error in if let error = error { print("Error adding: \\(error.localizedDescription)") } else { print("User successfully added!") } } }
func readUsers() { db.