How to add Firestore to an iOS app
What Firestore does for an iOS app
Firestore stores data as JSON-like documents grouped into collections, which suits app data like notes, posts, or chat messages. Its defining feature is realtime sync: attach a listener to a query and the device receives every change as it happens, so your views stay current without polling. It also works offline, caching reads and queuing writes until the network returns. Because the data model is schemaless, you can ship and evolve features without migrations, at the cost of doing your own shape validation in rules and code.
Adding Firestore with AppFlight
In AppFlight you connect Firebase from the integrations panel, and Firestore comes with it. AppFlight adds the FirebaseFirestore package, includes your GoogleService-Info.plist, and calls FirebaseApp.configure() at launch. The plist is a client file and safe to ship. AppFlight does not embed any Admin SDK credential, which is the secret one and belongs server-side. You can then ask the AI to model a collection, add a snapshot listener, or write a Codable type, and it generates the SwiftUI and the data layer for you.
A SwiftUI example
Map a Codable model to a collection, listen for changes, and add a document:
import SwiftUI
import FirebaseFirestore
struct Note: Identifiable, Codable {
@DocumentID var id: String?
var text: String
var createdAt: Date
}
@MainActor
final class NotesStore: ObservableObject {
@Published var notes: [Note] = []
private let db = Firestore.firestore()
private var listener: ListenerRegistration?
func start() {
listener = db.collection("notes")
.order(by: "createdAt", descending: true)
.addSnapshotListener { snapshot, _ in
self.notes = snapshot?.documents.compactMap {
try? $0.data(as: Note.self)
} ?? []
}
}
func add(_ text: String) throws {
try db.collection("notes").addDocument(
from: Note(text: text, createdAt: Date())
)
}
}
Bind the store with @StateObject, call start() in a task, and render notes in a List. Each insert appears on every signed-in device through the listener.
Alternatives
Supabase gives you Postgres with row-level security and SQL queries, which is the better fit for relational data and reporting, and it is AppFlight's keystone backend. CloudKit keeps everything inside the user's iCloud account with no server keys at all, which suits private per-user data. Firestore is the strongest choice when realtime document sync across devices is the core of the feature.
FAQ
Is Firestore realtime?
Yes. A snapshot listener pushes changes to the device as they happen, so a SwiftUI list updates without manual refresh. Firestore also caches data offline and reconciles when the device reconnects.
What protects Firestore data if the config ships in the app?
Firestore Security Rules. The GoogleService-Info.plist holds identifiers, not a secret, so anyone can see it, but rules decide which signed-in user can read or write each document. Leaving rules open is the common mistake, not shipping the config.
Firestore or a SQL database?
Firestore is a NoSQL document store that is great for realtime sync and flexible shapes. If you want relational queries and SQL, Supabase on Postgres fits better, and AppFlight uses Supabase as its keystone. Choose Firestore when realtime documents matter more than joins.