Challenge - 5 Problems
Firestore Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ ui_behavior
intermediate2:00remaining
Firestore Data Fetching Behavior
You have this Swift code snippet to fetch a document from Firestore and update a label. What will be the label's text if the document does not exist?
iOS Swift
let db = Firestore.firestore() db.collection("users").document("user123").getDocument { document, error in if let document = document, document.exists { label.text = document.get("name") as? String ?? "No Name" } else { label.text = "Document not found" } }
Attempts:
2 left
💡 Hint
Check the condition that tests if the document exists.
✗ Incorrect
If the document does not exist, the else block runs and sets the label text to "Document not found".
🧠 Conceptual
intermediate1:30remaining
Firestore Offline Persistence
What happens when Firestore offline persistence is enabled and the device loses internet connection?
Attempts:
2 left
💡 Hint
Think about how offline apps should behave to keep working.
✗ Incorrect
Enabling offline persistence allows Firestore to cache data locally and serve reads from cache when offline, syncing changes when back online.
📝 Syntax
advanced2:00remaining
Correct Firestore Document Update Syntax
Which option correctly updates the "age" field to 30 in the Firestore document "users/user123"?
iOS Swift
let db = Firestore.firestore() db.collection("users").document("user123").updateData(["age": 30]) { error in if let error = error { print("Error updating document: \(error)") } else { print("Document successfully updated") } }
Attempts:
2 left
💡 Hint
Look for the method that updates fields without overwriting the whole document.
✗ Incorrect
updateData is the correct method to update specific fields. setData overwrites the whole document. update and updateData with wrong parameters cause errors.
❓ lifecycle
advanced1:30remaining
Firestore Listener Behavior on App Backgrounding
If you add a Firestore snapshot listener in your iOS app, what happens to the listener when the app goes to the background?
Attempts:
2 left
💡 Hint
Think about how Firestore listeners behave unless you remove them.
✗ Incorrect
Firestore listeners remain active in background unless you remove them, which can affect battery and data usage.
🔧 Debug
expert2:30remaining
Diagnosing Firestore Permission Denied Error
You get a "Permission denied" error when trying to read a Firestore collection in your iOS app. Which is the most likely cause?
Attempts:
2 left
💡 Hint
Check your Firestore security rules first when you see permission errors.
✗ Incorrect
Permission denied errors usually mean Firestore security rules block access. Network or ID issues cause different errors.