diff --git a/Firestore/Example/Tests/Integration/API/FIRFirestoreSourceTests.mm b/Firestore/Example/Tests/Integration/API/FIRFirestoreSourceTests.mm index 012baad990b..14f531ed0d6 100644 --- a/Firestore/Example/Tests/Integration/API/FIRFirestoreSourceTests.mm +++ b/Firestore/Example/Tests/Integration/API/FIRFirestoreSourceTests.mm @@ -704,7 +704,7 @@ - (void)testGetNonExistingCollectionWhileOfflineServerOnly { // Document Reference - (void)DocumentReferenceDemo_addSnapshotListenerWithDefaultListenOptions { FIRDocumentReference *doc = [self.db documentWithPath:@"cities/SF"]; - FIRSnapshotListenOptions *options = [[FIRSnapshotListenOptions alloc] initWithDefaultOptions]; + FIRSnapshotListenOptions *options = [[FIRSnapshotListenOptions alloc] init]; [doc addSnapshotListenerWithOptions:options listener:^(FIRDocumentSnapshot *snapshot, NSError *error) { @@ -715,7 +715,7 @@ - (void)DocumentReferenceDemo_addSnapshotListenerWithDefaultListenOptions { - (void)DocumentReferenceDemo_addSnapshotListenerWithMetadataChanges { FIRDocumentReference *doc = [self.db documentWithPath:@"cities/SF"]; - FIRSnapshotListenOptions *options = [[FIRSnapshotListenOptions alloc] initWithDefaultOptions]; + FIRSnapshotListenOptions *options = [[FIRSnapshotListenOptions alloc] init]; FIRSnapshotListenOptions *optionsWithMetadata = [options withIncludeMetadataChanges:YES]; [doc addSnapshotListenerWithOptions:optionsWithMetadata @@ -727,7 +727,7 @@ - (void)DocumentReferenceDemo_addSnapshotListenerWithMetadataChanges { - (void)DocumentReferenceDemo_addSnapshotListenerFromCache { FIRDocumentReference *doc = [self.db documentWithPath:@"cities/SF"]; - FIRSnapshotListenOptions *options = [[FIRSnapshotListenOptions alloc] initWithDefaultOptions]; + FIRSnapshotListenOptions *options = [[FIRSnapshotListenOptions alloc] init]; FIRSnapshotListenOptions *optionsFromCache = [options withSource:FIRListenSourceCache]; [doc addSnapshotListenerWithOptions:optionsFromCache @@ -739,7 +739,7 @@ - (void)DocumentReferenceDemo_addSnapshotListenerFromCache { - (void)DocumentReferenceDemo_addSnapshotListenerFromCacheAndIncludeMetadataChanges { FIRDocumentReference *doc = [self.db documentWithPath:@"cities/SF"]; - FIRSnapshotListenOptions *options = [[FIRSnapshotListenOptions alloc] initWithDefaultOptions]; + FIRSnapshotListenOptions *options = [[FIRSnapshotListenOptions alloc] init]; FIRSnapshotListenOptions *optionsFromCacheAndWithMetadata = [[options withIncludeMetadataChanges:YES] withSource:FIRListenSourceCache]; @@ -754,7 +754,7 @@ - (void)DocumentReferenceDemo_addSnapshotListenerFromCacheAndIncludeMetadataChan - (void)QueryDemo_addSnapshotListenerWithDefaultListenOptions { FIRCollectionReference *collection = [self.db collectionWithPath:@"cities"]; FIRQuery *query = [collection queryWhereField:@"state" isEqualTo:@ "CA"]; - FIRSnapshotListenOptions *options = [[FIRSnapshotListenOptions alloc] initWithDefaultOptions]; + FIRSnapshotListenOptions *options = [[FIRSnapshotListenOptions alloc] init]; [query addSnapshotListenerWithOptions:options listener:^(FIRQuerySnapshot *snapshot, NSError *error) { @@ -766,7 +766,7 @@ - (void)QueryDemo_addSnapshotListenerWithDefaultListenOptions { - (void)QueryDemo_addSnapshotListenerWithMetadataChanges { FIRCollectionReference *collection = [self.db collectionWithPath:@"cities"]; FIRQuery *query = [collection queryWhereField:@"state" isEqualTo:@ "CA"]; - FIRSnapshotListenOptions *options = [[FIRSnapshotListenOptions alloc] initWithDefaultOptions]; + FIRSnapshotListenOptions *options = [[FIRSnapshotListenOptions alloc] init]; FIRSnapshotListenOptions *optionsWithMetadata = [options withIncludeMetadataChanges:YES]; [query addSnapshotListenerWithOptions:optionsWithMetadata @@ -779,7 +779,7 @@ - (void)QueryDemo_addSnapshotListenerWithMetadataChanges { - (void)QueryDemo_addSnapshotListenerFromCache { FIRCollectionReference *collection = [self.db collectionWithPath:@"cities"]; FIRQuery *query = [collection queryWhereField:@"state" isEqualTo:@ "CA"]; - FIRSnapshotListenOptions *options = [[FIRSnapshotListenOptions alloc] initWithDefaultOptions]; + FIRSnapshotListenOptions *options = [[FIRSnapshotListenOptions alloc] init]; FIRSnapshotListenOptions *optionsFromCache = [options withSource:FIRListenSourceCache]; [query addSnapshotListenerWithOptions:optionsFromCache @@ -792,7 +792,7 @@ - (void)QueryDemo_addSnapshotListenerFromCache { - (void)QueryDemo_addSnapshotListenerFromCacheAndIncludeMetadataChanges { FIRCollectionReference *collection = [self.db collectionWithPath:@"cities"]; FIRQuery *query = [collection queryWhereField:@"state" isEqualTo:@ "CA"]; - FIRSnapshotListenOptions *options = [[FIRSnapshotListenOptions alloc] initWithDefaultOptions]; + FIRSnapshotListenOptions *options = [[FIRSnapshotListenOptions alloc] init]; FIRSnapshotListenOptions *optionsFromCacheAndWithMetadata = [[options withIncludeMetadataChanges:YES] withSource:FIRListenSourceCache]; diff --git a/Firestore/Source/API/FIRSnapshotListenOptions.mm b/Firestore/Source/API/FIRSnapshotListenOptions.mm index 23f22565ac3..93fe4791923 100644 --- a/Firestore/Source/API/FIRSnapshotListenOptions.mm +++ b/Firestore/Source/API/FIRSnapshotListenOptions.mm @@ -28,7 +28,7 @@ @implementation FIRSnapshotListenOptions // private method - (instancetype)initPrivateWithSource:(FIRListenSource)source includeMetadataChanges:(BOOL)includeMetadataChanges { - self = [self initWithDefaultOptions]; + self = [self init]; if (self) { _source = source; _includeMetadataChanges = includeMetadataChanges; @@ -36,7 +36,7 @@ - (instancetype)initPrivateWithSource:(FIRListenSource)source return self; } -- (instancetype)initWithDefaultOptions { +- (instancetype)init { self = [super init]; if (self) { _source = FIRListenSourceDefault; diff --git a/Firestore/Source/Public/FirebaseFirestore/FIRSnapshotListenOptions.h b/Firestore/Source/Public/FirebaseFirestore/FIRSnapshotListenOptions.h index 099016a2362..1f56b1462db 100644 --- a/Firestore/Source/Public/FirebaseFirestore/FIRSnapshotListenOptions.h +++ b/Firestore/Source/Public/FirebaseFirestore/FIRSnapshotListenOptions.h @@ -29,8 +29,7 @@ NS_SWIFT_NAME(SnapshotListenOptions) @property(nonatomic, readonly) FIRListenSource source; @property(nonatomic, readonly) BOOL includeMetadataChanges; -- (instancetype)init NS_UNAVAILABLE; -- (instancetype)initWithDefaultOptions NS_DESIGNATED_INITIALIZER; +- (instancetype)init NS_DESIGNATED_INITIALIZER; - (FIRSnapshotListenOptions *)withIncludeMetadataChanges:(BOOL)includeMetadataChanges; - (FIRSnapshotListenOptions *)withSource:(FIRListenSource)source; diff --git a/Firestore/Swift/Tests/Integration/QueryIntegrationTests.swift b/Firestore/Swift/Tests/Integration/QueryIntegrationTests.swift index 2608bd5cc05..b70fe23ff12 100644 --- a/Firestore/Swift/Tests/Integration/QueryIntegrationTests.swift +++ b/Firestore/Swift/Tests/Integration/QueryIntegrationTests.swift @@ -335,4 +335,52 @@ class QueryIntegrationTests: FSTIntegrationTestCase { matchesResult: ["doc6", "doc3"] ) } + + public func Demo_addSnapshotListenerCurrentMethod(db: Firestore) async throws { + let query = db.collection("cities").whereField("state", isEqualTo:"CA") + query.addSnapshotListener(includeMetadataChanges: true) { documentSnapshot, error in + // ... + } +} + +public func Demo_addSnapshotListenerWithDefaultListenOptions(db: Firestore) async throws { + let query = db.collection("cities").whereField("state", isEqualTo:"CA") + let options = SnapshotListenOptions() + + query.addSnapshotListener(options:options) { documentSnapshot, error in + // ... + } +} + +public func Demo_addSnapshotListenerWithMetadataChanges(db: Firestore) async throws { + let query = db.collection("cities").whereField("state", isEqualTo:"CA") + let options = SnapshotListenOptions() + .withIncludeMetadataChanges(true) + + query.addSnapshotListener(options:options) { documentSnapshot, error in + // ... + } +} + +public func Demo_addSnapshotListenerFromCache(db: Firestore) async throws { + let query = db.collection("cities").whereField("state", isEqualTo:"CA") + let options = SnapshotListenOptions() + .withSource(.cache) + + query.addSnapshotListener(options:options) { documentSnapshot, error in + // ... + } +} + +public func Demo_addSnapshotListenerFromCacheAndIncludeMetadataChanges(db: Firestore) async throws { + let query = db.collection("cities").whereField("state", isEqualTo:"CA") + let options = SnapshotListenOptions() + .withSource(.cache) + .withIncludeMetadataChanges(true) + + query.addSnapshotListener(options:options) { documentSnapshot, error in + // ... + } +} + }