diff --git a/Firestore/Example/SwiftBuildTest/main.swift b/Firestore/Example/SwiftBuildTest/main.swift index c74c3d8b7b3..f87388e4555 100644 --- a/Firestore/Example/SwiftBuildTest/main.swift +++ b/Firestore/Example/SwiftBuildTest/main.swift @@ -228,11 +228,11 @@ func readDocument(at docRef: DocumentReference) { func readDocumentWithOptions(at docRef: DocumentReference) { docRef.getDocument(options:GetOptions.defaultOptions()) { document, error in } - docRef.getDocument(options:GetOptions.source(GetSource.default)) { document, error in + docRef.getDocument(options:GetOptions().source(GetSource.default)) { document, error in } - docRef.getDocument(options:GetOptions.source(.server)) { document, error in + docRef.getDocument(options:GetOptions().source(.server)) { document, error in } - docRef.getDocument(options:GetOptions.source(GetSource.cache)) { document, error in + docRef.getDocument(options:GetOptions().source(GetSource.cache)) { document, error in } } @@ -249,11 +249,11 @@ func readDocuments(matching query: Query) { func readDocumentsWithOptions(matching query: Query) { query.getDocuments(options:GetOptions.defaultOptions()) { querySnapshot, error in } - query.getDocuments(options:GetOptions.source(GetSource.default)) { querySnapshot, error in + query.getDocuments(options:GetOptions().source(GetSource.default)) { querySnapshot, error in } - query.getDocuments(options:GetOptions.source(.server)) { querySnapshot, error in + query.getDocuments(options:GetOptions().source(.server)) { querySnapshot, error in } - query.getDocuments(options:GetOptions.source(GetSource.cache)) { querySnapshot, error in + query.getDocuments(options:GetOptions().source(GetSource.cache)) { querySnapshot, error in } } diff --git a/Firestore/Example/Tests/Integration/API/FIRGetOptionsTests.m b/Firestore/Example/Tests/Integration/API/FIRGetOptionsTests.m index cf77d4ab0c5..22d71feb3e6 100644 --- a/Firestore/Example/Tests/Integration/API/FIRGetOptionsTests.m +++ b/Firestore/Example/Tests/Integration/API/FIRGetOptionsTests.m @@ -145,7 +145,8 @@ - (void)testGetDocumentWhileOnlineCacheOnly { // get doc and ensure that it exists, *is* from the cache, and matches // the initialData. FIRDocumentSnapshot *result = - [self readDocumentForRef:doc options:[FIRGetOptions optionsWithSource:FIRGetSourceCache]]; + [self readDocumentForRef:doc + options:[[[FIRGetOptions alloc] init] optionsWithSource:FIRGetSourceCache]]; XCTAssertTrue(result.exists); XCTAssertTrue(result.metadata.fromCache); XCTAssertFalse(result.metadata.hasPendingWrites); @@ -165,8 +166,9 @@ - (void)testGetCollectionWhileOnlineCacheOnly { // get docs and ensure they *are* from the cache, and matches the // initialDocs. - FIRQuerySnapshot *result = - [self readDocumentSetForRef:col options:[FIRGetOptions optionsWithSource:FIRGetSourceCache]]; + FIRQuerySnapshot *result = [self + readDocumentSetForRef:col + options:[[[FIRGetOptions alloc] init] optionsWithSource:FIRGetSourceCache]]; XCTAssertTrue(result.metadata.fromCache); XCTAssertFalse(result.metadata.hasPendingWrites); XCTAssertEqualObjects(FIRQuerySnapshotGetData(result), (@[ @@ -203,7 +205,8 @@ - (void)testGetDocumentWhileOfflineCacheOnly { // get doc and ensure it exists, *is* from the cache, and matches the // newData. FIRDocumentSnapshot *result = - [self readDocumentForRef:doc options:[FIRGetOptions optionsWithSource:FIRGetSourceCache]]; + [self readDocumentForRef:doc + options:[[[FIRGetOptions alloc] init] optionsWithSource:FIRGetSourceCache]]; XCTAssertTrue(result.exists); XCTAssertTrue(result.metadata.fromCache); XCTAssertTrue(result.metadata.hasPendingWrites); @@ -233,8 +236,9 @@ - (void)testGetCollectionWhileOfflineCacheOnly { // get docs and ensure they *are* from the cache, and matches the updated // data. - FIRQuerySnapshot *result = - [self readDocumentSetForRef:col options:[FIRGetOptions optionsWithSource:FIRGetSourceCache]]; + FIRQuerySnapshot *result = [self + readDocumentSetForRef:col + options:[[[FIRGetOptions alloc] init] optionsWithSource:FIRGetSourceCache]]; XCTAssertTrue(result.metadata.fromCache); XCTAssertTrue(result.metadata.hasPendingWrites); XCTAssertEqualObjects(FIRQuerySnapshotGetData(result), (@[ @@ -260,7 +264,8 @@ - (void)testGetDocumentWhileOnlineServerOnly { // get doc and ensure that it exists, is *not* from the cache, and matches // the initialData. FIRDocumentSnapshot *result = - [self readDocumentForRef:doc options:[FIRGetOptions optionsWithSource:FIRGetSourceServer]]; + [self readDocumentForRef:doc + options:[[[FIRGetOptions alloc] init] optionsWithSource:FIRGetSourceServer]]; XCTAssertTrue(result.exists); XCTAssertFalse(result.metadata.fromCache); XCTAssertFalse(result.metadata.hasPendingWrites); @@ -280,8 +285,9 @@ - (void)testGetCollectionWhileOnlineServerOnly { // get docs and ensure they are *not* from the cache, and matches the // initialData. - FIRQuerySnapshot *result = - [self readDocumentSetForRef:col options:[FIRGetOptions optionsWithSource:FIRGetSourceServer]]; + FIRQuerySnapshot *result = [self + readDocumentSetForRef:col + options:[[[FIRGetOptions alloc] init] optionsWithSource:FIRGetSourceServer]]; XCTAssertFalse(result.metadata.fromCache); XCTAssertFalse(result.metadata.hasPendingWrites); XCTAssertEqualObjects(FIRQuerySnapshotGetData(result), (@[ @@ -308,7 +314,7 @@ - (void)testGetDocumentWhileOfflineServerOnly { // attempt to get doc and ensure it cannot be retreived XCTestExpectation *failedGetDocCompletion = [self expectationWithDescription:@"failedGetDoc"]; - [doc getDocumentWithOptions:[FIRGetOptions optionsWithSource:FIRGetSourceServer] + [doc getDocumentWithOptions:[[[FIRGetOptions alloc] init] optionsWithSource:FIRGetSourceServer] completion:^(FIRDocumentSnapshot *snapshot, NSError *error) { XCTAssertNotNil(error); XCTAssertEqualObjects(error.domain, FIRFirestoreErrorDomain); @@ -334,7 +340,7 @@ - (void)testGetCollectionWhileOfflineServerOnly { // attempt to get docs and ensure they cannot be retreived XCTestExpectation *failedGetDocsCompletion = [self expectationWithDescription:@"failedGetDocs"]; - [col getDocumentsWithOptions:[FIRGetOptions optionsWithSource:FIRGetSourceServer] + [col getDocumentsWithOptions:[[[FIRGetOptions alloc] init] optionsWithSource:FIRGetSourceServer] completion:^(FIRQuerySnapshot *snapshot, NSError *error) { XCTAssertNotNil(error); XCTAssertEqualObjects(error.domain, FIRFirestoreErrorDomain); @@ -374,15 +380,17 @@ - (void)testGetDocumentWhileOfflineWithDifferentGetOptions { // get doc (from cache) and ensure it exists, *is* from the cache, and // matches the newData. FIRDocumentSnapshot *result = - [self readDocumentForRef:doc options:[FIRGetOptions optionsWithSource:FIRGetSourceCache]]; + [self readDocumentForRef:doc + options:[[[FIRGetOptions alloc] init] optionsWithSource:FIRGetSourceCache]]; XCTAssertTrue(result.exists); XCTAssertTrue(result.metadata.fromCache); XCTAssertTrue(result.metadata.hasPendingWrites); XCTAssertEqualObjects(result.data, newData); // attempt to get doc (with default get options) - result = - [self readDocumentForRef:doc options:[FIRGetOptions optionsWithSource:FIRGetSourceDefault]]; + result = [self + readDocumentForRef:doc + options:[[[FIRGetOptions alloc] init] optionsWithSource:FIRGetSourceDefault]]; XCTAssertTrue(result.exists); XCTAssertTrue(result.metadata.fromCache); XCTAssertTrue(result.metadata.hasPendingWrites); @@ -390,7 +398,7 @@ - (void)testGetDocumentWhileOfflineWithDifferentGetOptions { // attempt to get doc (from the server) and ensure it cannot be retreived XCTestExpectation *failedGetDocCompletion = [self expectationWithDescription:@"failedGetDoc"]; - [doc getDocumentWithOptions:[FIRGetOptions optionsWithSource:FIRGetSourceServer] + [doc getDocumentWithOptions:[[[FIRGetOptions alloc] init] optionsWithSource:FIRGetSourceServer] completion:^(FIRDocumentSnapshot *snapshot, NSError *error) { XCTAssertNotNil(error); XCTAssertEqualObjects(error.domain, FIRFirestoreErrorDomain); @@ -432,8 +440,9 @@ - (void)testGetCollectionWhileOfflineWithDifferentGetOptions { // get docs (from cache) and ensure they *are* from the cache, and // matches the updated data. - FIRQuerySnapshot *result = - [self readDocumentSetForRef:col options:[FIRGetOptions optionsWithSource:FIRGetSourceCache]]; + FIRQuerySnapshot *result = [self + readDocumentSetForRef:col + options:[[[FIRGetOptions alloc] init] optionsWithSource:FIRGetSourceCache]]; XCTAssertTrue(result.metadata.fromCache); XCTAssertTrue(result.metadata.hasPendingWrites); XCTAssertEqualObjects(FIRQuerySnapshotGetData(result), (@[ @@ -449,8 +458,9 @@ - (void)testGetCollectionWhileOfflineWithDifferentGetOptions { ])); // attempt to get docs (with default get options) - result = [self readDocumentSetForRef:col - options:[FIRGetOptions optionsWithSource:FIRGetSourceDefault]]; + result = [self + readDocumentSetForRef:col + options:[[[FIRGetOptions alloc] init] optionsWithSource:FIRGetSourceDefault]]; XCTAssertTrue(result.metadata.fromCache); XCTAssertEqualObjects(FIRQuerySnapshotGetData(result), (@[ @{@"key1" : @"value1"}, @{@"key2" : @"value2", @"key2b" : @"value2b"}, @@ -466,7 +476,7 @@ - (void)testGetCollectionWhileOfflineWithDifferentGetOptions { // attempt to get docs (from the server) and ensure they cannot be retreived XCTestExpectation *failedGetDocsCompletion = [self expectationWithDescription:@"failedGetDocs"]; - [col getDocumentsWithOptions:[FIRGetOptions optionsWithSource:FIRGetSourceServer] + [col getDocumentsWithOptions:[[[FIRGetOptions alloc] init] optionsWithSource:FIRGetSourceServer] completion:^(FIRQuerySnapshot *snapshot, NSError *error) { XCTAssertNotNil(error); XCTAssertEqualObjects(error.domain, FIRFirestoreErrorDomain); @@ -539,7 +549,7 @@ - (void)testGetNonExistingDocWhileOnlineCacheOnly { // certain documents *don't* exist. XCTestExpectation *getNonExistingDocCompletion = [self expectationWithDescription:@"getNonExistingDoc"]; - [doc getDocumentWithOptions:[FIRGetOptions optionsWithSource:FIRGetSourceCache] + [doc getDocumentWithOptions:[[[FIRGetOptions alloc] init] optionsWithSource:FIRGetSourceCache] completion:^(FIRDocumentSnapshot *snapshot, NSError *error) { XCTAssertNotNil(error); XCTAssertEqualObjects(error.domain, FIRFirestoreErrorDomain); @@ -553,8 +563,9 @@ - (void)testGetNonExistingCollectionWhileOnlineCacheOnly { FIRCollectionReference *col = [self collectionRef]; // get collection and ensure it's empty and that it *is* from the cache. - FIRQuerySnapshot *snapshot = - [self readDocumentSetForRef:col options:[FIRGetOptions optionsWithSource:FIRGetSourceCache]]; + FIRQuerySnapshot *snapshot = [self + readDocumentSetForRef:col + options:[[[FIRGetOptions alloc] init] optionsWithSource:FIRGetSourceCache]]; XCTAssertEqual(snapshot.count, 0); XCTAssertEqual(snapshot.documentChanges.count, 0); XCTAssertTrue(snapshot.metadata.fromCache); @@ -572,7 +583,7 @@ - (void)testGetNonExistingDocWhileOfflineCacheOnly { // certain documents *don't* exist. XCTestExpectation *getNonExistingDocCompletion = [self expectationWithDescription:@"getNonExistingDoc"]; - [doc getDocumentWithOptions:[FIRGetOptions optionsWithSource:FIRGetSourceCache] + [doc getDocumentWithOptions:[[[FIRGetOptions alloc] init] optionsWithSource:FIRGetSourceCache] completion:^(FIRDocumentSnapshot *snapshot, NSError *error) { XCTAssertNotNil(error); XCTAssertEqualObjects(error.domain, FIRFirestoreErrorDomain); @@ -589,8 +600,9 @@ - (void)testGetNonExistingCollectionWhileOfflineCacheOnly { [self disableNetwork]; // get collection and ensure it's empty and that it *is* from the cache. - FIRQuerySnapshot *snapshot = - [self readDocumentSetForRef:col options:[FIRGetOptions optionsWithSource:FIRGetSourceCache]]; + FIRQuerySnapshot *snapshot = [self + readDocumentSetForRef:col + options:[[[FIRGetOptions alloc] init] optionsWithSource:FIRGetSourceCache]]; XCTAssertEqual(snapshot.count, 0); XCTAssertEqual(snapshot.documentChanges.count, 0); XCTAssertTrue(snapshot.metadata.fromCache); @@ -602,7 +614,8 @@ - (void)testGetNonExistingDocWhileOnlineServerOnly { // get doc and ensure that it does not exist and is *not* from the cache. FIRDocumentSnapshot *snapshot = - [self readDocumentForRef:doc options:[FIRGetOptions optionsWithSource:FIRGetSourceServer]]; + [self readDocumentForRef:doc + options:[[[FIRGetOptions alloc] init] optionsWithSource:FIRGetSourceServer]]; XCTAssertFalse(snapshot.exists); XCTAssertFalse(snapshot.metadata.fromCache); XCTAssertFalse(snapshot.metadata.hasPendingWrites); @@ -612,8 +625,9 @@ - (void)testGetNonExistingCollectionWhileOnlineServerOnly { FIRCollectionReference *col = [self collectionRef]; // get collection and ensure that it's empty and that it's *not* from the cache. - FIRQuerySnapshot *snapshot = - [self readDocumentSetForRef:col options:[FIRGetOptions optionsWithSource:FIRGetSourceServer]]; + FIRQuerySnapshot *snapshot = [self + readDocumentSetForRef:col + options:[[[FIRGetOptions alloc] init] optionsWithSource:FIRGetSourceServer]]; XCTAssertEqual(snapshot.count, 0); XCTAssertEqual(snapshot.documentChanges.count, 0); XCTAssertFalse(snapshot.metadata.fromCache); @@ -631,7 +645,7 @@ - (void)testGetNonExistingDocWhileOfflineServerOnly { // certain documents *don't* exist. XCTestExpectation *getNonExistingDocCompletion = [self expectationWithDescription:@"getNonExistingDoc"]; - [doc getDocumentWithOptions:[FIRGetOptions optionsWithSource:FIRGetSourceServer] + [doc getDocumentWithOptions:[[[FIRGetOptions alloc] init] optionsWithSource:FIRGetSourceServer] completion:^(FIRDocumentSnapshot *snapshot, NSError *error) { XCTAssertNotNil(error); XCTAssertEqualObjects(error.domain, FIRFirestoreErrorDomain); @@ -649,7 +663,7 @@ - (void)testGetNonExistingCollectionWhileOfflineServerOnly { // attempt to get collection and ensure that it cannot be retreived XCTestExpectation *failedGetDocsCompletion = [self expectationWithDescription:@"failedGetDocs"]; - [col getDocumentsWithOptions:[FIRGetOptions optionsWithSource:FIRGetSourceServer] + [col getDocumentsWithOptions:[[[FIRGetOptions alloc] init] optionsWithSource:FIRGetSourceServer] completion:^(FIRQuerySnapshot *snapshot, NSError *error) { XCTAssertNotNil(error); XCTAssertEqualObjects(error.domain, FIRFirestoreErrorDomain); diff --git a/Firestore/Source/API/FIRGetOptions+Internal.h b/Firestore/Source/API/FIRGetOptions+Internal.h index da3bdc9de6b..1e8a479c837 100644 --- a/Firestore/Source/API/FIRGetOptions+Internal.h +++ b/Firestore/Source/API/FIRGetOptions+Internal.h @@ -23,8 +23,6 @@ NS_ASSUME_NONNULL_BEGIN /** Where getDocument[s] calls should get their data from. */ @property(nonatomic, readonly, getter=source) FIRGetSource source; -- (instancetype)initWithSource:(FIRGetSource)source; - @end NS_ASSUME_NONNULL_END diff --git a/Firestore/Source/API/FIRGetOptions.m b/Firestore/Source/API/FIRGetOptions.m index e43f25f837b..a3af44a9a3e 100644 --- a/Firestore/Source/API/FIRGetOptions.m +++ b/Firestore/Source/API/FIRGetOptions.m @@ -21,18 +21,19 @@ @implementation FIRGetOptions + (instancetype)defaultOptions { - return [[FIRGetOptions alloc] initWithSource:FIRGetSourceDefault]; + return [[FIRGetOptions alloc] init]; } -- (instancetype)initWithSource:(FIRGetSource)source { +- (instancetype)init { if (self = [super init]) { - _source = source; + _source = FIRGetSourceDefault; } return self; } -+ (instancetype)optionsWithSource:(FIRGetSource)source { - return [[FIRGetOptions alloc] initWithSource:source]; +- (instancetype)optionsWithSource:(FIRGetSource)source { + _source = source; + return self; } @end diff --git a/Firestore/Source/Public/FIRGetOptions.h b/Firestore/Source/Public/FIRGetOptions.h index de283255ecf..8242e3e16ef 100644 --- a/Firestore/Source/Public/FIRGetOptions.h +++ b/Firestore/Source/Public/FIRGetOptions.h @@ -28,9 +28,6 @@ NS_ASSUME_NONNULL_BEGIN NS_SWIFT_NAME(GetOptions) @interface FIRGetOptions : NSObject -/** */ -- (instancetype)init __attribute((unavailable("FIRGetOptions cannot be created directly."))); - /** * Returns the default options. * @@ -65,7 +62,7 @@ typedef NS_ENUM(NSUInteger, FIRGetSource) { /** * Initializes the get options with the specified source. */ -+ (instancetype)optionsWithSource:(FIRGetSource)source NS_SWIFT_NAME(source(_:)); +- (instancetype)optionsWithSource:(FIRGetSource)source NS_SWIFT_NAME(source(_:)); @end