Complete the code to import the Firestore module in Swift.
import [1]
You need to import FirebaseFirestore to use Firestore features in your Swift app.
Complete the code to get a Firestore database instance.
let db = Firestore.[1]()Use Firestore.firestore() to get the default Firestore database instance.
Fix the error in the code to add data to a Firestore collection.
db.collection("users").[1](data: ["name": "Alice", "age": 30]) { error in if let error = error { print("Error adding document: \(error)") } else { print("Document added successfully") } }
Use addDocument(data:completion:) to add a new document with data to a collection.
Fill both blanks to read documents from a Firestore collection and print their data.
db.collection("products").[1] { querySnapshot, error in if let error = error { print("Error getting documents: \(error)") } else { for document in [2]?.documents ?? [] { print(document.data()) } } }
Use getDocuments to fetch documents once, and querySnapshot holds the result.
Fill all three blanks to update a specific document's field in Firestore.
let docRef = db.collection("orders").document([1]) docRef.[2](["status": [3]]) { error in if let error = error { print("Error updating document: \(error)") } else { print("Document successfully updated") } }
Use document("order123") to get the document, updateData to update fields, and set the status to "shipped".