Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 21 additions & 20 deletions Firestore/Example/SwiftBuildTest/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func main() {

listenToDocuments(matching: query);

enableDisableNetwork(db: db);
enableDisableNetwork(database: db);

types();
}
Expand Down Expand Up @@ -133,7 +133,7 @@ func writeDocument(at docRef: DocumentReference) {
}
}

func enableDisableNetwork(db db: Firestore) {
func enableDisableNetwork(database db: Firestore) {
// closure syntax
db.disableNetwork(completion: { (error) in
if let e = error {
Expand Down Expand Up @@ -235,26 +235,27 @@ func readDocuments(matching query: Query) {

func listenToDocument(at docRef: DocumentReference) {

let listener = docRef.addSnapshotListener() { document, error in
if let error = error {
print("Uh oh! Listen canceled: \(error)")
return
}
let listener = docRef.addSnapshotListener() { document, error in
if let error = error {
print("Uh oh! Listen canceled: \(error)")
return
}

if let document = document {
// Note that document.data() is nullable.
let data : [String:Any]? = document.data()
print("Current document: \(data)");
if (document.metadata.isFromCache) {
print("From Cache")
} else {
print("From Server")
}
}
if let document = document {
// Note that document.data() is nullable.
if let data : [String:Any] = document.data() {
print("Current document: \(data)");
}
if document.metadata.isFromCache {
print("From Cache")
} else {
print("From Server")
}
}
}

// Unsubscribe.
listener.remove();
// Unsubscribe.
listener.remove();
}

func listenToDocuments(matching query: Query) {
Expand Down Expand Up @@ -316,7 +317,7 @@ func transactions() {
let balanceA = try transaction.getDocument(accA)["balance"] as! Double
let balanceB = try transaction.getDocument(accB)["balance"] as! Double

if (balanceA < amount) {
if balanceA < amount {
errorPointer?.pointee = NSError(domain: "Foo", code: 123, userInfo: nil)
return nil
}
Expand Down
4 changes: 4 additions & 0 deletions Firestore/Example/Tests/API/FIRQueryTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ @interface FIRQueryTests : XCTestCase
@implementation FIRQueryTests

- (void)testFilteringWithPredicate {
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wnonnull"
// Everything is dummy for unit test here. Filtering does not require any app
// specific setting as far as we do not fetch data.
FIRFirestore *firestore = [[FIRFirestore alloc] initWithProjectID:@"abc"
Expand All @@ -41,6 +43,8 @@ - (void)testFilteringWithPredicate {
credentialsProvider:nil
workerDispatchQueue:nil
firebaseApp:nil];
#pragma clang diagnostic pop

FSTResourcePath *path = [FSTResourcePath pathWithString:@"foo"];
FIRQuery *query = [FIRQuery referenceWithQuery:[FSTQuery queryWithPath:path] firestore:firestore];
FIRQuery *query1 = [query queryWhereField:@"f" isLessThanOrEqualTo:@1];
Expand Down
2 changes: 2 additions & 0 deletions Firestore/Example/Tests/Integration/API/FIRQueryTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,8 @@ - (void)testQueriesFireFromCacheWhenOffline {
[self enableNetwork];
querySnap = [self.eventAccumulator awaitEventWithName:@"back online event with isFromCache=NO"];
XCTAssertEqual(querySnap.metadata.isFromCache, NO);

[registration remove];
}

@end