aboutsummaryrefslogtreecommitdiffhomepage
path: root/Firestore/Example/SwiftBuildTest/main.swift
diff options
context:
space:
mode:
authorGravatar Sebastian Schmidt <mrschmidt@google.com>2017-12-14 11:03:41 +0800
committerGravatar Sebastian Schmidt <mrschmidt@google.com>2017-12-14 11:04:45 +0800
commit08bd327bbfd352ecac783528300c55f1d738e4ae (patch)
tree92584edc3d4613f5c56896eb0465dfedc6f04032 /Firestore/Example/SwiftBuildTest/main.swift
parent2dd7324bd543027e2925e7e653ca83a7bad3c31b (diff)
Adding Swift build test
Diffstat (limited to 'Firestore/Example/SwiftBuildTest/main.swift')
-rw-r--r--Firestore/Example/SwiftBuildTest/main.swift25
1 files changed, 19 insertions, 6 deletions
diff --git a/Firestore/Example/SwiftBuildTest/main.swift b/Firestore/Example/SwiftBuildTest/main.swift
index 475c1b2..c05f378 100644
--- a/Firestore/Example/SwiftBuildTest/main.swift
+++ b/Firestore/Example/SwiftBuildTest/main.swift
@@ -167,11 +167,20 @@ func readDocument(at docRef: DocumentReference) {
// Trailing closure syntax.
docRef.getDocument() { document, error in
if let document = document {
- // NOTE that document is nullable.
- let data = document.data();
+ // Note that both document and document.data() is nullable.
+ if let data = document.data() {
print("Read document: \(data)")
-
- // Fields are read via subscript notation.
+ }
+ if let data = document.data(with:SnapshotOptions.serverTimestampBehavior(.estimate)) {
+ print("Read document: \(data)")
+ }
+ if let foo = document.get("foo") {
+ print("Field: \(foo)")
+ }
+ if let foo = document.get("foo", options: SnapshotOptions.serverTimestampBehavior(.previous)) {
+ print("Field: \(foo)")
+ }
+ // Fields can also be read via subscript notation.
if let foo = document["foo"] {
print("Field: \(foo)")
}
@@ -214,7 +223,9 @@ func listenToDocument(at docRef: DocumentReference) {
}
if let document = document {
- print("Current document: \(document.data())");
+ // Note that document.data() is nullable.
+ let data : [String:Any]? = document.data()
+ print("Current document: \(data)");
if (document.metadata.isFromCache) {
print("From Cache")
} else {
@@ -241,7 +252,9 @@ func listenToDocuments(matching query: Query) {
// TODO(mikelehen): Figure out how to make "for..in" syntax work
// directly on documentSet.
for document in snap.documents {
- print("Doc: ", document.data())
+ // Note that document.data() is not nullable.
+ let data : [String:Any] = document.data()
+ print("Doc: ", data)
}
}
}