sharing-firestore

0.2.0

A lightweight wrapper for Firebase's Firestore database that integrates with the Sharing library.
bitkey-oss/sharing-firestore

What's New

0.2.0

2025-04-08T07:57:32Z

SharingFirestore v0.2.0 Release Notes

Key Features

  • supporting "orFilter", "andFilter", "isNotEqualTo"
  • Improve internal hashability

SharingFirestore

A lightweight wrapper for Firebase's Firestore database that integrates with the Sharing library.

A swift library that extends the swift-sharing library with support for Firebase's Firestore.

Overview

SharingFirestore is a lightweight wrapper for working with Firebase's Firestore via the Sharing library.

By integrating with Sharing, you can combine Firestore's powerful real-time database capabilities with Sharing's powerful observation functions. You can synchronize data across devices with the ease of UserDefaults, and you can keep your UI updated in real-time, similar to how SwiftUI's @Observable works.

This project is inspired by SharingGRDB and provides a convenient wrapper for using Firestore in SwiftUI and UIKit applications. Thanks to pointfreeco for publishing this great library.

Quick start

Before SharingFirestore's property wrappers can fetch data from Firestore, you need to provide—at runtime—the default Firestore instance it should use. This is typically done as early as possible in your app's lifetime, like the app entry point in SwiftUI:

import SharingFirestore
import SwiftUI

@main
struct MyApp: App {
  init() {
    prepareDependencies {
      FirebaseApp.configure()
      $0.defaultFirestore = Firestore.firestore()
    }
  }
  // ...
}

Note: For more information on preparing Firestore, see Preparing Firestore.

This defaultFirestore connection is used implicitly by SharingFirestore's strategies:

@Shared(
    .sync(
      configuration: .init(
        collectionPath: "todos",
        orderBy: .desc("createdAt"),
        animation: .default
      )
    )
  )
private var todos: IdentifiedArrayOf<Todo>
@SharedReader(
    .query(
      configuration: .init(
        path: "facts",
        predicates: [.order(by: "count", descending: true)],
        animation: .default
      )
    )
  )
private var facts: IdentifiedArrayOf<Fact>

And you can access the Firestore database throughout your application using the dependency system:

@Dependency(\.defaultFirestore)
var database

try database.collection("todos").addDocument(from: Todo(memo: "New todo", completed: false))

This is all you need to know to get started with SharingFirestore, but there's much more to learn. Read the articles below to learn how to best utilize this library:

Demos

This repo comes with several examples to demonstrate how to solve common and complex problems with SharingFirestore. Check out this directory to see them all, including:

  • Case Studies: A number of case studies demonstrating the built-in features of the library, including querying, syncing, dynamic queries, and integration with @Observable models.

Documentation

The documentation for releases and main are available here:

Installation

You can add SharingFirestore to an Xcode project by adding it to your project as a package.

https://github.com/bitkey-oss/sharing-firestore

If you want to use SharingFirestore in a SwiftPM project, it's as simple as adding it to your Package.swift:

dependencies: [
  .package(url: "https://github.com/bitkey-oss/sharing-firestore", from: "0.1.0")
]

And then adding the products to any target that needs access to the libraries:

.product(name: "SharingFirestore", package: "sharing-firestore"),

License

This library is released under the MIT license. See LICENSE for details.

Description

  • Swift Tools 6.0.0
View More Packages from this Author

Dependencies

Last updated: Mon May 12 2025 04:09:13 GMT-0900 (Hawaii-Aleutian Daylight Time)