Convert Figma logo to code with AI

firebase logofirebase-ios-sdk

Firebase SDK for Apple App Development

5,608
1,472
5,608
416

Top Related Projects

The Apple SDK for Parse Platform (iOS, macOS, watchOS, tvOS)

Realm is a mobile database: a replacement for Core Data & SQLite

40,982

Elegant HTTP Networking in Swift

Promises for Swift & ObjC.

Quick Overview

The firebase/firebase-ios-sdk repository contains the official open-source Firebase SDK for iOS and tvOS. It provides a comprehensive suite of tools and services for building and managing mobile applications, including real-time database, authentication, cloud storage, and more.

Pros

  • Comprehensive suite of tools and services for mobile app development
  • Seamless integration with other Google and Firebase products
  • Regular updates and active community support
  • Extensive documentation and learning resources

Cons

  • Can be complex to set up and configure for beginners
  • Potential vendor lock-in to Google's ecosystem
  • Some features may require paid plans for larger-scale applications
  • Performance impact on app size and runtime, especially for smaller apps

Code Examples

  1. Initialize Firebase in your app:
import Firebase

class AppDelegate: UIResponder, UIApplicationDelegate {
    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
        FirebaseApp.configure()
        return true
    }
}
  1. Authenticate a user with email and password:
import FirebaseAuth

Auth.auth().signIn(withEmail: email, password: password) { (authResult, error) in
    if let error = error {
        print("Error: \(error.localizedDescription)")
    } else {
        print("User signed in successfully")
    }
}
  1. Write data to Firestore:
import FirebaseFirestore

let db = Firestore.firestore()
db.collection("users").document("user1").setData([
    "name": "John Doe",
    "age": 30,
    "email": "john@example.com"
]) { err in
    if let err = err {
        print("Error writing document: \(err)")
    } else {
        print("Document successfully written")
    }
}

Getting Started

  1. Install CocoaPods if not already installed:

    sudo gem install cocoapods
    
  2. Create a Podfile in your Xcode project directory:

    pod init
    
  3. Add Firebase pods to your Podfile:

    pod 'Firebase/Analytics'
    pod 'Firebase/Auth'
    pod 'Firebase/Firestore'
    
  4. Install the pods:

    pod install
    
  5. Open the .xcworkspace file instead of the .xcodeproj file.

  6. Add the Firebase configuration file to your project and initialize Firebase in your AppDelegate as shown in the code examples above.

Competitor Comparisons

The Apple SDK for Parse Platform (iOS, macOS, watchOS, tvOS)

Pros of Parse-SDK-iOS-OSX

  • Open-source and community-driven, allowing for more flexibility and customization
  • Supports self-hosting, giving developers full control over their backend infrastructure
  • Offers a more straightforward setup process for basic applications

Cons of Parse-SDK-iOS-OSX

  • Less frequent updates and potentially slower bug fixes compared to Firebase
  • Smaller ecosystem and fewer integrated services than Firebase's comprehensive platform
  • May require more manual configuration and maintenance for advanced features

Code Comparison

Parse-SDK-iOS-OSX:

let object = PFObject(className: "MyClass")
object["key"] = "value"
object.saveInBackground { (success, error) in
    if success {
        print("Object saved!")
    }
}

firebase-ios-sdk:

let db = Firestore.firestore()
db.collection("myCollection").addDocument(data: [
    "key": "value"
]) { err in
    if let err = err {
        print("Error adding document: \(err)")
    } else {
        print("Document added successfully")
    }
}

Both SDKs offer similar functionality for basic operations like saving data, but Firebase's SDK is more tightly integrated with other Google services. Parse-SDK-iOS-OSX provides a simpler API for common tasks, while Firebase offers more advanced features out of the box. The choice between the two depends on specific project requirements, desired level of control, and the need for additional services beyond basic backend functionality.

Realm is a mobile database: a replacement for Core Data & SQLite

Pros of Realm Swift

  • Faster performance for local data operations
  • Simpler API and easier learning curve
  • Supports offline-first development with automatic sync

Cons of Realm Swift

  • Limited cloud services compared to Firebase
  • Smaller community and ecosystem
  • Less comprehensive documentation and tutorials

Code Comparison

Firebase iOS SDK:

let db = Firestore.firestore()
db.collection("users").document("user1").setData([
    "name": "John Doe",
    "age": 30
]) { err in
    if let err = err {
        print("Error writing document: \(err)")
    } else {
        print("Document successfully written!")
    }
}

Realm Swift:

let realm = try! Realm()
try! realm.write {
    let user = User()
    user.name = "John Doe"
    user.age = 30
    realm.add(user)
}

Both Firebase iOS SDK and Realm Swift are popular choices for iOS app development, offering different strengths. Firebase provides a comprehensive suite of cloud services, while Realm excels in local data management and offline-first development. The choice between them depends on specific project requirements and developer preferences.

40,982

Elegant HTTP Networking in Swift

Pros of Alamofire

  • Lightweight and focused on networking tasks
  • Simpler setup and integration for basic HTTP requests
  • More flexible and customizable for specific networking needs

Cons of Alamofire

  • Limited to networking functionality, unlike Firebase's comprehensive suite
  • Requires more manual implementation for features like authentication and real-time updates
  • Less built-in support for offline persistence and synchronization

Code Comparison

Alamofire HTTP request:

AF.request("https://api.example.com/data").responseJSON { response in
    switch response.result {
    case .success(let value):
        print("Success: \(value)")
    case .failure(let error):
        print("Error: \(error)")
    }
}

Firebase Firestore read operation:

db.collection("users").document("user1").getDocument { (document, error) in
    if let document = document, document.exists {
        let data = document.data()
        print("Document data: \(data)")
    } else {
        print("Document does not exist")
    }
}

While Alamofire excels in simplicity for network requests, Firebase iOS SDK offers a more comprehensive solution for app development, including real-time database, authentication, and cloud functions. The choice between them depends on the specific needs of your project and the desired level of integration with other services.

Promises for Swift & ObjC.

Pros of PromiseKit

  • Lightweight and focused on asynchronous programming
  • Easier to learn and implement for specific async tasks
  • More flexible and can be used with various APIs and frameworks

Cons of PromiseKit

  • Limited to handling asynchronous operations
  • Requires additional libraries for features like real-time updates
  • Less comprehensive ecosystem compared to Firebase

Code Comparison

PromiseKit:

firstly {
    fetchUser(id: 123)
}.then { user in
    updateProfile(for: user)
}.done { result in
    print("Profile updated: \(result)")
}.catch { error in
    print("Error: \(error)")
}

Firebase iOS SDK:

let db = Firestore.firestore()
db.collection("users").document("123").getDocument { (document, error) in
    if let document = document, document.exists {
        // Update user profile
    } else {
        print("Document does not exist")
    }
}

PromiseKit focuses on simplifying asynchronous code with a chainable syntax, while Firebase iOS SDK provides a more comprehensive set of tools for various backend services, including real-time database operations.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README


Firebase Apple Open Source Development

This repository contains the source code for all Apple platform Firebase SDKs except FirebaseAnalytics.

Firebase is an app development platform with tools to help you build, grow, and monetize your app. More information about Firebase can be found on the official Firebase website.

Installation

See the subsections below for details about the different installation methods. Where available, it's recommended to install any libraries with a Swift suffix to get the best experience when writing your app in Swift.

  1. Standard pod install
  2. Swift Package Manager
  3. Installing from the GitHub repo
  4. Experimental Carthage

Standard pod install

For instructions on the standard pod install, visit: https://firebase.google.com/docs/ios/setup.

Swift Package Manager

Instructions for Swift Package Manager support can be found in the SwiftPackageManager.md Markdown file.

Installing from GitHub

These instructions can be used to access the Firebase repo at other branches, tags, or commits.

Background

See the Podfile Syntax Reference for instructions and options about overriding pod source locations.

Accessing Firebase Source Snapshots

All official releases are tagged in this repo and available via CocoaPods. To access a local source snapshot or unreleased branch, use Podfile directives like the following:

To access FirebaseFirestore via a branch:

pod 'FirebaseCore', :git => 'https://github.com/firebase/firebase-ios-sdk.git', :branch => 'main'
pod 'FirebaseFirestore', :git => 'https://github.com/firebase/firebase-ios-sdk.git', :branch => 'main'

To access FirebaseMessaging via a checked-out version of the firebase-ios-sdk repo:

pod 'FirebaseCore', :path => '/path/to/firebase-ios-sdk'
pod 'FirebaseMessaging', :path => '/path/to/firebase-ios-sdk'

Carthage (iOS only)

Instructions for the experimental Carthage distribution can be found at Carthage.md.

Using Firebase from a Framework or a library

For details on using Firebase from a Framework or a library, refer to firebase_in_libraries.md.

Development

To develop Firebase software in this repository, ensure that you have at least the following software:

  • Xcode 15.2 (or later)

CocoaPods is still the canonical way to develop, but much of the repo now supports development with Swift Package Manager.

CocoaPods

Install the following:

For the pod that you want to develop:

pod gen Firebase{name here}.podspec --local-sources=./ --auto-open --platforms=ios

Note: If the CocoaPods cache is out of date, you may need to run pod repo update before the pod gen command.

Note: Set the --platforms option to macos or tvos to develop/test for those platforms. Since 10.2, Xcode does not properly handle multi-platform CocoaPods workspaces.

Firestore has a self-contained Xcode project. See Firestore/README Markdown file.

Development for Catalyst

  • pod gen {name here}.podspec --local-sources=./ --auto-open --platforms=ios
  • Check the Mac box in the App-iOS Build Settings
  • Sign the App in the Settings Signing & Capabilities tab
  • Click Pods in the Project Manager
  • Add Signing to the iOS host app and unit test targets
  • Select the Unit-unit scheme
  • Run it to build and test

Alternatively, disable signing in each target:

  • Go to Build Settings tab
  • Click +
  • Select Add User-Defined Setting
  • Add CODE_SIGNING_REQUIRED setting with a value of NO

Swift Package Manager

  • To enable test schemes: ./scripts/setup_spm_tests.sh
  • open Package.swift or double click Package.swift in Finder.
  • Xcode will open the project
    • Choose a scheme for a library to build or test suite to run
    • Choose a target platform by selecting the run destination along with the scheme

Adding a New Firebase Pod

Refer to AddNewPod Markdown file for details.

Managing Headers and Imports

For information about managing headers and imports, see HeadersImports Markdown file.

Code Formatting

To ensure that the code is formatted consistently, run the script ./scripts/check.sh before creating a pull request (PR).

GitHub Actions will verify that any code changes are done in a style-compliant way. Install clang-format and mint:

brew install clang-format@19
brew install mint

Running Unit Tests

Select a scheme and press Command-u to build a component and run its unit tests.

Running Sample Apps

To run the sample apps and integration tests, you'll need a valid GoogleService-Info.plist file. The Firebase Xcode project contains dummy plist files without real values, but they can be replaced with real plist files. To get your own GoogleService-Info.plist files:

  1. Go to the Firebase Console
  2. Create a new Firebase project, if you don't already have one
  3. For each sample app you want to test, create a new Firebase app with the sample app's bundle identifier (e.g., com.google.Database-Example)
  4. Download the resulting GoogleService-Info.plist and add it to the Xcode project.

Coverage Report Generation

For coverage report generation instructions, see scripts/code_coverage_report/README Markdown file.

Specific Component Instructions

See the sections below for any special instructions for those components.

Firebase Auth

For specific Firebase Auth development, refer to the Auth Sample README for instructions about building and running the FirebaseAuth pod along with various samples and tests.

Firebase Database

The Firebase Database Integration tests can be run against a locally running Database Emulator or against a production instance.

To run against a local emulator instance, invoke ./scripts/run_database_emulator.sh start before running the integration test.

To run against a production instance, provide a valid GoogleServices-Info.plist and copy it to FirebaseDatabase/Tests/Resources/GoogleService-Info.plist. Your Security Rule must be set to public while your tests are running.

Firebase Dynamic Links

Firebase Dynamic Links is deprecated and should not be used in new projects. The service will shut down on August 25, 2025.

Please see our Dynamic Links Deprecation FAQ documentation for more guidance.

Firebase Performance Monitoring

For specific Firebase Performance Monitoring development, see the Performance README for instructions about building the SDK and the Performance TestApp README for instructions about integrating Performance with the dev test App.

Firebase Storage

To run the Storage Integration tests, follow the instructions in StorageIntegration.swift.

Push Notifications

Push notifications can only be delivered to specially provisioned App IDs in the developer portal. In order to test receiving push notifications, you will need to:

  1. Change the bundle identifier of the sample app to something you own in your Apple Developer account and enable that App ID for push notifications.
  2. You'll also need to upload your APNs Provider Authentication Key or certificate to the Firebase Console at Project Settings > Cloud Messaging > [Your Firebase App].
  3. Ensure your iOS device is added to your Apple Developer portal as a test device.

iOS Simulator

The iOS Simulator cannot register for remote notifications and will not receive push notifications. To receive push notifications, follow the steps above and run the app on a physical device.

Vertex AI for Firebase

See the Vertex AI for Firebase README for instructions about building and testing the SDK.

Building with Firebase on Apple platforms

Firebase provides official beta support for macOS, Catalyst, and tvOS. visionOS and watchOS are community supported. Thanks to community contributions for many of the multi-platform PRs.

At this time, most of Firebase's products are available across Apple platforms. There are still a few gaps, especially on visionOS and watchOS. For details about the current support matrix, see this chart in Firebase's documentation.

visionOS

Where supported, visionOS works as expected with the exception of Firestore via Swift Package Manager where it is required to use the source distribution.

To enable the Firestore source distribution, quit Xcode and open the desired project from the command line with the FIREBASE_SOURCE_FIRESTORE environment variable: open --env FIREBASE_SOURCE_FIRESTORE /path/to/project.xcodeproj. To go back to using the binary distribution of Firestore, quit Xcode and open Xcode like normal, without the environment variable.

watchOS

Thanks to contributions from the community, many of Firebase SDKs now compile, run unit tests, and work on watchOS. See the Independent Watch App Sample.

Keep in mind that watchOS is not officially supported by Firebase. While we can catch basic unit test issues with GitHub Actions, there may be some changes where the SDK no longer works as expected on watchOS. If you encounter this, please file an issue.

During app setup in the console, you may get to a step that mentions something like "Checking if the app has communicated with our servers". This relies on Analytics and will not work on watchOS. It's safe to ignore the message and continue, the rest of the SDKs will work as expected.

Additional Crashlytics Notes

  • watchOS has limited support. Due to watchOS restrictions, mach exceptions and signal crashes are not recorded. (Crashes in SwiftUI are generated as mach exceptions, so will not be recorded)

Combine

Thanks to contributions from the community, FirebaseCombineSwift contains support for Apple's Combine framework. This module is currently under development and not yet supported for use in production environments. For more details, please refer to the docs.

Roadmap

See Roadmap for more about the Firebase Apple SDK Open Source plans and directions.

Contributing

See Contributing for more information on contributing to the Firebase Apple SDK.

License

The contents of this repository are licensed under the Apache License, version 2.0.

Your use of Firebase is governed by the Terms of Service for Firebase Services.