0
0
iOS Swiftmobile~20 mins

Cloud Firestore in iOS Swift - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Firestore Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
ui_behavior
intermediate
2: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"
  }
}
A"Document not found"
B"No Name"
CApp crashes with nil error
D"" (empty string)
Attempts:
2 left
💡 Hint
Check the condition that tests if the document exists.
🧠 Conceptual
intermediate
1:30remaining
Firestore Offline Persistence
What happens when Firestore offline persistence is enabled and the device loses internet connection?
AFirestore caches data locally and serves reads from cache until connection is restored
BFirestore stops all reads and writes until internet is back
CFirestore deletes all cached data immediately
DFirestore automatically switches to a backup server
Attempts:
2 left
💡 Hint
Think about how offline apps should behave to keep working.
📝 Syntax
advanced
2: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")
  }
}
Adb.collection("users").document("user123").update(["age": 30])
Bdb.collection("users").document("user123").setData(["age": 30])
Cdb.collection("users").document("user123").updateData(["age": 30]) { error in ... }
Ddb.collection("users").document("user123").updateData("age", 30)
Attempts:
2 left
💡 Hint
Look for the method that updates fields without overwriting the whole document.
lifecycle
advanced
1: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?
AListener automatically stops and resumes when app returns to foreground
BListener continues to receive updates until explicitly removed
CListener causes app crash in background
DListener pauses and never resumes
Attempts:
2 left
💡 Hint
Think about how Firestore listeners behave unless you remove them.
🔧 Debug
expert
2: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?
AThe app is missing internet permission in Info.plist
BThe Firestore database is offline
CThe document ID is invalid
DFirestore security rules do not allow read access to the collection
Attempts:
2 left
💡 Hint
Check your Firestore security rules first when you see permission errors.