Convert Figma logo to code with AI

firebase logoquickstart-ios

Firebase Quickstart Samples for iOS

2,792
1,472
2,792
37

Top Related Projects

🔥 A well-tested feature-rich modular Firebase implementation for React Native. Supports both iOS & Android platforms for all Firebase services.

Firebase SDK for Apple App Development

Firebase Quickstart Samples for Android

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

Promises for Swift & ObjC.

Quick Overview

The firebase/quickstart-ios repository is a collection of sample iOS applications demonstrating various Firebase features and integrations. It provides developers with practical examples and starter code for implementing Firebase services in iOS apps using Swift.

Pros

  • Comprehensive coverage of Firebase features for iOS
  • Well-documented and regularly updated examples
  • Includes both UIKit and SwiftUI implementations
  • Serves as a valuable learning resource for iOS developers

Cons

  • Some examples may not cover advanced use cases
  • Requires basic knowledge of iOS development and Swift
  • May not always reflect the latest Firebase SDK versions immediately
  • Limited to iOS platform-specific implementations

Code Examples

  1. Adding Firebase to your iOS app:
import UIKit
import FirebaseCore

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
    func application(_ application: UIApplication,
                     didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
        FirebaseApp.configure()
        return true
    }
}
  1. Authenticating a user with Firebase Authentication:
import FirebaseAuth

Auth.auth().signIn(withEmail: email, password: password) { (authResult, error) in
    if let error = error {
        print("Error: \(error.localizedDescription)")
        return
    }
    // User is signed in
    let user = authResult?.user
    print("User signed in: \(user?.uid ?? "")")
}
  1. Writing data to Firebase Realtime Database:
import FirebaseDatabase

let ref = Database.database().reference()
ref.child("users").child(userId).setValue(["username": username]) { (error, ref) in
    if let error = error {
        print("Data could not be saved: \(error).")
    } else {
        print("Data saved successfully!")
    }
}

Getting Started

  1. Clone the repository:

    git clone https://github.com/firebase/quickstart-ios.git
    
  2. Navigate to the desired sample app directory:

    cd quickstart-ios/authentication
    
  3. Install dependencies using CocoaPods:

    pod install
    
  4. Open the .xcworkspace file in Xcode:

    open Authentication.xcworkspace
    
  5. Set up a Firebase project in the Firebase Console and download the GoogleService-Info.plist file.

  6. Add the GoogleService-Info.plist file to your Xcode project.

  7. Build and run the app in Xcode.

Competitor Comparisons

🔥 A well-tested feature-rich modular Firebase implementation for React Native. Supports both iOS & Android platforms for all Firebase services.

Pros of react-native-firebase

  • Cross-platform support for both iOS and Android
  • Comprehensive Firebase feature coverage in a single package
  • Active community and frequent updates

Cons of react-native-firebase

  • Steeper learning curve for developers new to React Native
  • Potential performance overhead due to JavaScript bridge

Code Comparison

quickstart-ios (Swift):

import Firebase

class AppDelegate: UIResponder, UIApplicationDelegate {
  func application(_ application: UIApplication,
                   didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
    FirebaseApp.configure()
    return true
  }
}

react-native-firebase (JavaScript):

import firebase from '@react-native-firebase/app';

function App() {
  useEffect(() => {
    firebase.initializeApp();
  }, []);

  return (
    // Your app components
  );
}

Summary

quickstart-ios provides native iOS examples for Firebase integration, offering optimal performance and direct access to iOS-specific features. It's ideal for developers focusing solely on iOS.

react-native-firebase enables Firebase integration in React Native apps, supporting both iOS and Android. It offers a unified API and extensive feature coverage but may have a steeper learning curve for native iOS developers.

Choose based on your project requirements, target platforms, and team expertise.

Firebase SDK for Apple App Development

Pros of firebase-ios-sdk

  • More comprehensive and feature-rich, providing full SDK implementation
  • Allows for deeper customization and integration with iOS apps
  • Regularly updated with new Firebase features and improvements

Cons of firebase-ios-sdk

  • Larger file size and potentially increased app bundle size
  • Steeper learning curve for developers new to Firebase
  • May require more setup and configuration compared to quickstart samples

Code Comparison

firebase-ios-sdk (Objective-C):

#import <FirebaseCore/FirebaseCore.h>

[FIRApp configure];
FIRFirestore *db = [FIRFirestore firestore];

quickstart-ios (Swift):

import Firebase

FirebaseApp.configure()
let db = Firestore.firestore()

Summary

firebase-ios-sdk is the full Firebase SDK for iOS, offering comprehensive features and customization options. It's ideal for developers who need deep integration and access to all Firebase capabilities. However, it comes with a larger footprint and may require more setup.

quickstart-ios provides sample code and basic implementations for various Firebase features. It's great for beginners or those looking to quickly prototype Firebase functionality in their iOS apps. While it offers easier setup and smaller file size, it may lack some advanced features and customization options available in the full SDK.

Choose firebase-ios-sdk for production apps requiring full Firebase functionality, and quickstart-ios for learning, prototyping, or simpler implementations.

Firebase Quickstart Samples for Android

Pros of quickstart-android

  • More comprehensive sample apps, covering a wider range of Firebase features
  • Better documentation and comments within the code samples
  • More frequent updates and maintenance

Cons of quickstart-android

  • Larger repository size, potentially making it harder to navigate
  • Some samples may be more complex, which could be overwhelming for beginners

Code Comparison

quickstart-android (Kotlin):

private fun getInstanceId() {
    FirebaseInstanceId.getInstance().instanceId
        .addOnCompleteListener(OnCompleteListener { task ->
            if (!task.isSuccessful) {
                Log.w(TAG, "getInstanceId failed", task.exception)
                return@OnCompleteListener
            }
            val token = task.result?.token
            val msg = getString(R.string.msg_token_fmt, token)
            Log.d(TAG, msg)
            Toast.makeText(baseContext, msg, Toast.LENGTH_SHORT).show()
        })
}

quickstart-ios (Swift):

func messaging(_ messaging: Messaging, didReceiveRegistrationToken fcmToken: String?) {
  print("Firebase registration token: \(String(describing: fcmToken))")

  let dataDict: [String: String] = ["token": fcmToken ?? ""]
  NotificationCenter.default.post(
    name: Notification.Name("FCMToken"),
    object: nil,
    userInfo: dataDict
  )
}

Both repositories provide excellent starting points for developers looking to integrate Firebase into their mobile applications. While quickstart-android offers more comprehensive samples and documentation, quickstart-ios provides a more streamlined experience for iOS developers. The code examples demonstrate similar functionality but showcase the language-specific implementations for each platform.

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

Pros of Parse-SDK-iOS-OSX

  • Open-source and self-hostable, providing more control over data and infrastructure
  • Extensive documentation and community support
  • Flexible and customizable, allowing for more tailored solutions

Cons of Parse-SDK-iOS-OSX

  • Requires more setup and maintenance compared to Firebase's managed services
  • May have fewer built-in features and integrations out of the box
  • Potentially slower development time due to increased configuration needs

Code Comparison

Parse-SDK-iOS-OSX:

let gameScore = PFObject(className: "GameScore")
gameScore["score"] = 1337
gameScore["playerName"] = "Sean Plott"
gameScore.saveInBackground { (success, error) in
    if success {
        print("Score saved successfully")
    } else {
        print("Error saving score: \(error?.localizedDescription ?? "")")
    }
}

Firebase quickstart-ios:

let db = Firestore.firestore()
db.collection("scores").addDocument(data: [
    "score": 1337,
    "playerName": "Sean Plott"
]) { err in
    if let err = err {
        print("Error adding document: \(err)")
    } else {
        print("Document added successfully")
    }
}

Both examples demonstrate saving data to their respective backends, with Firebase offering a slightly more concise syntax. Parse provides more flexibility in object creation, while Firebase's structure is more tightly coupled to its document-based model.

Promises for Swift & ObjC.

Pros of PromiseKit

  • Focused library for asynchronous programming with promises
  • Extensive documentation and community support
  • Lightweight and easy to integrate into existing projects

Cons of PromiseKit

  • Limited scope compared to Firebase's comprehensive suite of tools
  • Requires additional libraries for features like authentication or database management
  • Steeper learning curve for developers new to promise-based programming

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 Quickstart:

Auth.auth().signIn(withEmail: email, password: password) { (user, error) in
    if let error = error {
        print("Error: \(error.localizedDescription)")
        return
    }
    print("User signed in successfully")
}

PromiseKit focuses on chaining asynchronous operations using promises, while Firebase Quickstart provides ready-to-use implementations for various Firebase services. PromiseKit offers more flexibility in handling complex asynchronous flows, whereas Firebase Quickstart simplifies integration with Firebase's ecosystem.

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 Quickstarts for iOS

A collection of quickstart samples demonstrating the Firebase APIs on iOS. Each sample contains targets for both Objective-C and Swift. For more information, see https://firebase.google.com.

Samples

You can open each of the following samples as an Xcode project, and run them on a mobile device or a simulator. Simply install the pods and open the .xcworkspace file to see the project in Xcode.

$ pod install --repo-update
$ open your-project.xcworkspace

When doing so you need to add each sample app you wish to try to a Firebase project on the Firebase console. You can add multiple sample apps to the same Firebase project. There's no need to create separate projects for each app.

To add a sample app to a Firebase project, use the bundleID from the Xcode project. Download the generated GoogleService-Info.plist file, and replace the existing plist to the root directory of the sample you wish to run.

Code Formatting

To ensure that the code is formatted consistently, run the script ./scripts/style.sh before creating a PR.

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

brew install mint
mint bootstrap
./scripts/style.sh

How to make contributions?

Please read and follow the steps in the CONTRIBUTING.md

License

See LICENSE