From a5b3185ed372fc16b5430c230c197e3dbd34f953 Mon Sep 17 00:00:00 2001 From: rsgowman Date: Wed, 18 Apr 2018 10:30:37 -0400 Subject: Add GetOptions for controlling offline get behaviour (#655) Add option to allow the user to control where DocumentReference.getDocument() and CollectionReference.getDocuments() fetches from. By default, it fetches from the server (if possible) and falls back to the local cache. It's now possible to alternatively fetch from the local cache only, or to fetch from the server only (though in the server only case, latency compensation is still enabled). --- Firestore/Example/SwiftBuildTest/main.swift | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'Firestore/Example/SwiftBuildTest/main.swift') diff --git a/Firestore/Example/SwiftBuildTest/main.swift b/Firestore/Example/SwiftBuildTest/main.swift index 00839c4..f61da2b 100644 --- a/Firestore/Example/SwiftBuildTest/main.swift +++ b/Firestore/Example/SwiftBuildTest/main.swift @@ -32,8 +32,10 @@ func main() { addDocument(to: collectionRef) readDocument(at: documentRef) + readDocumentWithSource(at: documentRef) readDocuments(matching: query) + readDocumentsWithSource(matching: query) listenToDocument(at: documentRef) @@ -230,6 +232,15 @@ func readDocument(at docRef: DocumentReference) { } } +func readDocumentWithSource(at docRef: DocumentReference) { + docRef.getDocument(source: FirestoreSource.default) { document, error in + } + docRef.getDocument(source: .server) { document, error in + } + docRef.getDocument(source: FirestoreSource.cache) { document, error in + } +} + func readDocuments(matching query: Query) { query.getDocuments { querySnapshot, error in // TODO(mikelehen): Figure out how to make "for..in" syntax work @@ -240,6 +251,15 @@ func readDocuments(matching query: Query) { } } +func readDocumentsWithSource(matching query: Query) { + query.getDocuments(source: FirestoreSource.default) { querySnapshot, error in + } + query.getDocuments(source: .server) { querySnapshot, error in + } + query.getDocuments(source: FirestoreSource.cache) { querySnapshot, error in + } +} + func listenToDocument(at docRef: DocumentReference) { let listener = docRef.addSnapshotListener { document, error in if let error = error { -- cgit v1.2.3