Skip to content

Commit

Permalink
change initWithDefaultOptions to init
Browse files Browse the repository at this point in the history
  • Loading branch information
milaGGL committed Jan 3, 2024
1 parent 19ee487 commit d9e4857
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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];

Expand All @@ -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) {
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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];

Expand Down
4 changes: 2 additions & 2 deletions Firestore/Source/API/FIRSnapshotListenOptions.mm
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@ @implementation FIRSnapshotListenOptions
// private method
- (instancetype)initPrivateWithSource:(FIRListenSource)source
includeMetadataChanges:(BOOL)includeMetadataChanges {
self = [self initWithDefaultOptions];
self = [self init];
if (self) {
_source = source;
_includeMetadataChanges = includeMetadataChanges;
}
return self;
}

- (instancetype)initWithDefaultOptions {
- (instancetype)init {
self = [super init];
if (self) {
_source = FIRListenSourceDefault;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
48 changes: 48 additions & 0 deletions Firestore/Swift/Tests/Integration/QueryIntegrationTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
// ...
}
}

}

0 comments on commit d9e4857

Please sign in to comment.