From 5368c9e22f9a6b427466e9422645d688953013c0 Mon Sep 17 00:00:00 2001 From: Gil Date: Sun, 15 Apr 2018 13:06:06 -0700 Subject: Replace the `SetOptions` object with a simple boolean. (#1098) Instead of calling `setData(["a": "b"], options: SetOptions.merge())` call `setData(["a": "b"], merge: true)` --- Firestore/CHANGELOG.md | 3 ++ Firestore/Example/SwiftBuildTest/main.swift | 14 +++-- .../Tests/Integration/API/FIRDatabaseTests.mm | 8 +-- .../Tests/Integration/API/FIRValidationTests.mm | 6 +-- .../Tests/Integration/API/FIRWriteBatchTests.mm | 7 +-- .../Tests/Integration/FSTTransactionTests.mm | 7 +-- Firestore/Source/API/FIRDocumentReference.mm | 16 +++--- Firestore/Source/API/FIRSetOptions+Internal.h | 33 ------------ Firestore/Source/API/FIRSetOptions.mm | 63 ---------------------- Firestore/Source/API/FIRTransaction.mm | 9 ++-- Firestore/Source/API/FIRWriteBatch.mm | 9 ++-- Firestore/Source/API/FSTUserDataConverter.h | 3 +- Firestore/Source/API/FSTUserDataConverter.mm | 7 ++- Firestore/Source/Core/FSTTransaction.h | 1 - Firestore/Source/Core/FSTTransaction.mm | 1 - Firestore/Source/Public/FIRDocumentReference.h | 19 ++++--- Firestore/Source/Public/FIRSetOptions.h | 46 ---------------- Firestore/Source/Public/FIRTransaction.h | 11 ++-- Firestore/Source/Public/FIRWriteBatch.h | 11 ++-- Firestore/Source/Public/FirebaseFirestore.h | 1 - 20 files changed, 61 insertions(+), 214 deletions(-) delete mode 100644 Firestore/Source/API/FIRSetOptions+Internal.h delete mode 100644 Firestore/Source/API/FIRSetOptions.mm delete mode 100644 Firestore/Source/Public/FIRSetOptions.h (limited to 'Firestore') diff --git a/Firestore/CHANGELOG.md b/Firestore/CHANGELOG.md index 11df638..00e16f5 100644 --- a/Firestore/CHANGELOG.md +++ b/Firestore/CHANGELOG.md @@ -3,6 +3,9 @@ Instead of calling `addSnapshotListener(options: DocumentListenOptions.includeMetadataChanges(true))` call `addSnapshotListener(includeMetadataChanges:true)`. +- [changed] Replaced the `SetOptions` object with a simple boolean. Instead of + calling `setData(["a": "b"], options: SetOptions.merge())` call + `setData(["a": "b"], merge: true)`. # v0.11.0 - [fixed] Fixed a regression in the Firebase iOS SDK release 4.11.0 that could diff --git a/Firestore/Example/SwiftBuildTest/main.swift b/Firestore/Example/SwiftBuildTest/main.swift index 555a75b..ad6c0f6 100644 --- a/Firestore/Example/SwiftBuildTest/main.swift +++ b/Firestore/Example/SwiftBuildTest/main.swift @@ -118,8 +118,16 @@ func writeDocument(at docRef: DocumentReference) { print("Set complete!") } - // SetOptions - docRef.setData(setData, options: SetOptions.merge()) + // merge + docRef.setData(setData, merge: true) + docRef.setData(setData, merge: true) { error in + if let error = error { + print("Uh oh! \(error)") + return + } + + print("Set complete!") + } docRef.updateData(updateData) docRef.delete() @@ -156,6 +164,7 @@ func writeDocuments(at docRef: DocumentReference, database db: Firestore) { batch = db.batch() batch.setData(["a": "b"], forDocument: docRef) + batch.setData(["a": "b"], forDocument: docRef, merge: true) batch.setData(["c": "d"], forDocument: docRef) // commit without completion callback. batch.commit() @@ -355,7 +364,6 @@ func types() { let _: QueryListenOptions let _: Query let _: QuerySnapshot - let _: SetOptions let _: SnapshotMetadata let _: Transaction let _: WriteBatch diff --git a/Firestore/Example/Tests/Integration/API/FIRDatabaseTests.mm b/Firestore/Example/Tests/Integration/API/FIRDatabaseTests.mm index 503d50b..9b6febe 100644 --- a/Firestore/Example/Tests/Integration/API/FIRDatabaseTests.mm +++ b/Firestore/Example/Tests/Integration/API/FIRDatabaseTests.mm @@ -144,7 +144,7 @@ [self expectationWithDescription:@"testCanMergeDataWithAnExistingDocumentUsingSet"]; [doc setData:mergeData - options:[FIRSetOptions merge] + merge:YES completion:^(NSError *error) { XCTAssertNil(error); [completed fulfill]; @@ -171,7 +171,7 @@ [self expectationWithDescription:@"testCanMergeDataWithAnExistingDocumentUsingSet"]; [doc setData:mergeData - options:[FIRSetOptions merge] + merge:YES completion:^(NSError *error) { XCTAssertNil(error); [completed fulfill]; @@ -203,7 +203,7 @@ [self expectationWithDescription:@"testCanMergeDataWithAnExistingDocumentUsingSet"]; [doc setData:mergeData - options:[FIRSetOptions merge] + merge:YES completion:^(NSError *error) { XCTAssertNil(error); [completed fulfill]; @@ -244,7 +244,7 @@ [self expectationWithDescription:@"testCanMergeDataWithAnExistingDocumentUsingSet"]; [doc setData:mergeData - options:[FIRSetOptions merge] + merge:YES completion:^(NSError *error) { XCTAssertNil(error); [completed fulfill]; diff --git a/Firestore/Example/Tests/Integration/API/FIRValidationTests.mm b/Firestore/Example/Tests/Integration/API/FIRValidationTests.mm index 82c57c3..2c6a2a8 100644 --- a/Firestore/Example/Tests/Integration/API/FIRValidationTests.mm +++ b/Firestore/Example/Tests/Integration/API/FIRValidationTests.mm @@ -282,7 +282,7 @@ [self expectSet:@{@"foo" : [FIRFieldValue fieldValueForDelete]} toFailWithReason: @"FieldValue.delete() can only be used with updateData() and setData() with " - @"SetOptions.merge() (found in field foo)"]; + @"merge:true (found in field foo)"]; } - (void)testUpdatesWithNestedFieldValueDeleteFail { @@ -304,7 +304,7 @@ FIRDocumentReference *badRef = [db2 documentWithPath:@"foo/bar"]; FIRWriteBatch *batch = [db1 batch]; FSTAssertThrows([batch setData:data forDocument:badRef], reason); - FSTAssertThrows([batch setData:data forDocument:badRef options:[FIRSetOptions merge]], reason); + FSTAssertThrows([batch setData:data forDocument:badRef merge:YES], reason); FSTAssertThrows([batch updateData:data forDocument:badRef], reason); FSTAssertThrows([batch deleteDocument:badRef], reason); } @@ -322,7 +322,7 @@ [db1 runTransactionWithBlock:^id(FIRTransaction *txn, NSError **pError) { FSTAssertThrows([txn getDocument:badRef error:nil], reason); FSTAssertThrows([txn setData:data forDocument:badRef], reason); - FSTAssertThrows([txn setData:data forDocument:badRef options:[FIRSetOptions merge]], reason); + FSTAssertThrows([txn setData:data forDocument:badRef merge:YES], reason); FSTAssertThrows([txn updateData:data forDocument:badRef], reason); FSTAssertThrows([txn deleteDocument:badRef], reason); return nil; diff --git a/Firestore/Example/Tests/Integration/API/FIRWriteBatchTests.mm b/Firestore/Example/Tests/Integration/API/FIRWriteBatchTests.mm index b1d6738..3f2d64b 100644 --- a/Firestore/Example/Tests/Integration/API/FIRWriteBatchTests.mm +++ b/Firestore/Example/Tests/Integration/API/FIRWriteBatchTests.mm @@ -79,12 +79,7 @@ XCTestExpectation *batchExpectation = [self expectationWithDescription:@"batch written"]; FIRWriteBatch *batch = [doc.firestore batch]; [batch setData:@{ @"a" : @"b", @"nested" : @{@"a" : @"b"} } forDocument:doc]; - [batch setData:@{ - @"c" : @"d", - @"nested" : @{@"c" : @"d"} - } - forDocument:doc - options:[FIRSetOptions merge]]; + [batch setData:@{ @"c" : @"d", @"nested" : @{@"c" : @"d"} } forDocument:doc merge:YES]; [batch commitWithCompletion:^(NSError *error) { XCTAssertNil(error); [batchExpectation fulfill]; diff --git a/Firestore/Example/Tests/Integration/FSTTransactionTests.mm b/Firestore/Example/Tests/Integration/FSTTransactionTests.mm index 2464b0c..999987b 100644 --- a/Firestore/Example/Tests/Integration/FSTTransactionTests.mm +++ b/Firestore/Example/Tests/Integration/FSTTransactionTests.mm @@ -203,12 +203,7 @@ XCTestExpectation *expectation = [self expectationWithDescription:@"transaction"]; [firestore runTransactionWithBlock:^id _Nullable(FIRTransaction *transaction, NSError **error) { [transaction setData:@{ @"a" : @"b", @"nested" : @{@"a" : @"b"} } forDocument:doc]; - [transaction setData:@{ - @"c" : @"d", - @"nested" : @{@"c" : @"d"} - } - forDocument:doc - options:[FIRSetOptions merge]]; + [transaction setData:@{ @"c" : @"d", @"nested" : @{@"c" : @"d"} } forDocument:doc merge:YES]; return @YES; } completion:^(id _Nullable result, NSError *_Nullable error) { diff --git a/Firestore/Source/API/FIRDocumentReference.mm b/Firestore/Source/API/FIRDocumentReference.mm index d3a9295..2423472 100644 --- a/Firestore/Source/API/FIRDocumentReference.mm +++ b/Firestore/Source/API/FIRDocumentReference.mm @@ -28,7 +28,6 @@ #import "Firestore/Source/API/FIRDocumentSnapshot+Internal.h" #import "Firestore/Source/API/FIRFirestore+Internal.h" #import "Firestore/Source/API/FIRListenerRegistration+Internal.h" -#import "Firestore/Source/API/FIRSetOptions+Internal.h" #import "Firestore/Source/API/FSTUserDataConverter.h" #import "Firestore/Source/Core/FSTEventManager.h" #import "Firestore/Source/Core/FSTFirestoreClient.h" @@ -117,24 +116,23 @@ NS_ASSUME_NONNULL_BEGIN } - (void)setData:(NSDictionary *)documentData { - return [self setData:documentData options:[FIRSetOptions overwrite] completion:nil]; + return [self setData:documentData merge:NO completion:nil]; } -- (void)setData:(NSDictionary *)documentData options:(FIRSetOptions *)options { - return [self setData:documentData options:options completion:nil]; +- (void)setData:(NSDictionary *)documentData merge:(BOOL)merge { + return [self setData:documentData merge:merge completion:nil]; } - (void)setData:(NSDictionary *)documentData completion:(nullable void (^)(NSError *_Nullable error))completion { - return [self setData:documentData options:[FIRSetOptions overwrite] completion:completion]; + return [self setData:documentData merge:NO completion:completion]; } - (void)setData:(NSDictionary *)documentData - options:(FIRSetOptions *)options + merge:(BOOL)merge completion:(nullable void (^)(NSError *_Nullable error))completion { - FSTParsedSetData *parsed = options.isMerge - ? [self.firestore.dataConverter parsedMergeData:documentData] - : [self.firestore.dataConverter parsedSetData:documentData]; + FSTParsedSetData *parsed = merge ? [self.firestore.dataConverter parsedMergeData:documentData] + : [self.firestore.dataConverter parsedSetData:documentData]; return [self.firestore.client writeMutations:[parsed mutationsWithKey:self.key precondition:Precondition::None()] completion:completion]; diff --git a/Firestore/Source/API/FIRSetOptions+Internal.h b/Firestore/Source/API/FIRSetOptions+Internal.h deleted file mode 100644 index 9118096..0000000 --- a/Firestore/Source/API/FIRSetOptions+Internal.h +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright 2017 Google - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#import "FIRSetOptions.h" - -NS_ASSUME_NONNULL_BEGIN - -@interface FIRSetOptions () - -- (instancetype)initWithMerge:(BOOL)merge NS_DESIGNATED_INITIALIZER; - -@end - -@interface FIRSetOptions (Internal) - -+ (instancetype)overwrite; - -@end - -NS_ASSUME_NONNULL_END diff --git a/Firestore/Source/API/FIRSetOptions.mm b/Firestore/Source/API/FIRSetOptions.mm deleted file mode 100644 index b41086c..0000000 --- a/Firestore/Source/API/FIRSetOptions.mm +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Copyright 2017 Google - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#import "Firestore/Source/API/FIRSetOptions+Internal.h" - -NS_ASSUME_NONNULL_BEGIN - -@implementation FIRSetOptions - -- (instancetype)initWithMerge:(BOOL)merge { - if (self = [super init]) { - _merge = merge; - } - return self; -} - -+ (instancetype)merge { - return [[FIRSetOptions alloc] initWithMerge:YES]; -} - -- (BOOL)isEqual:(id)other { - if (self == other) { - return YES; - } else if (![other isKindOfClass:[FIRSetOptions class]]) { - return NO; - } - - FIRSetOptions *otherOptions = (FIRSetOptions *)other; - return otherOptions.merge == self.merge; -} - -- (NSUInteger)hash { - return self.merge ? 1231 : 1237; -} -@end - -@implementation FIRSetOptions (Internal) - -+ (instancetype)overwrite { - static FIRSetOptions *overwriteInstance = nil; - static dispatch_once_t onceToken; - dispatch_once(&onceToken, ^{ - overwriteInstance = [[FIRSetOptions alloc] initWithMerge:NO]; - }); - return overwriteInstance; -} - -@end - -NS_ASSUME_NONNULL_END diff --git a/Firestore/Source/API/FIRTransaction.mm b/Firestore/Source/API/FIRTransaction.mm index 2d1dd68..668a359 100644 --- a/Firestore/Source/API/FIRTransaction.mm +++ b/Firestore/Source/API/FIRTransaction.mm @@ -19,7 +19,6 @@ #import "Firestore/Source/API/FIRDocumentReference+Internal.h" #import "Firestore/Source/API/FIRDocumentSnapshot+Internal.h" #import "Firestore/Source/API/FIRFirestore+Internal.h" -#import "Firestore/Source/API/FIRSetOptions+Internal.h" #import "Firestore/Source/API/FSTUserDataConverter.h" #import "Firestore/Source/Core/FSTTransaction.h" #import "Firestore/Source/Model/FSTDocument.h" @@ -62,15 +61,15 @@ NS_ASSUME_NONNULL_BEGIN - (FIRTransaction *)setData:(NSDictionary *)data forDocument:(FIRDocumentReference *)document { - return [self setData:data forDocument:document options:[FIRSetOptions overwrite]]; + return [self setData:data forDocument:document merge:NO]; } - (FIRTransaction *)setData:(NSDictionary *)data forDocument:(FIRDocumentReference *)document - options:(FIRSetOptions *)options { + merge:(BOOL)merge { [self validateReference:document]; - FSTParsedSetData *parsed = options.isMerge ? [self.firestore.dataConverter parsedMergeData:data] - : [self.firestore.dataConverter parsedSetData:data]; + FSTParsedSetData *parsed = merge ? [self.firestore.dataConverter parsedMergeData:data] + : [self.firestore.dataConverter parsedSetData:data]; [self.internalTransaction setData:parsed forDocument:document.key]; return self; } diff --git a/Firestore/Source/API/FIRWriteBatch.mm b/Firestore/Source/API/FIRWriteBatch.mm index df6e5e0..1185dae 100644 --- a/Firestore/Source/API/FIRWriteBatch.mm +++ b/Firestore/Source/API/FIRWriteBatch.mm @@ -18,7 +18,6 @@ #import "Firestore/Source/API/FIRDocumentReference+Internal.h" #import "Firestore/Source/API/FIRFirestore+Internal.h" -#import "Firestore/Source/API/FIRSetOptions+Internal.h" #import "Firestore/Source/API/FSTUserDataConverter.h" #import "Firestore/Source/Core/FSTFirestoreClient.h" #import "Firestore/Source/Model/FSTMutation.h" @@ -63,16 +62,16 @@ NS_ASSUME_NONNULL_BEGIN - (FIRWriteBatch *)setData:(NSDictionary *)data forDocument:(FIRDocumentReference *)document { - return [self setData:data forDocument:document options:[FIRSetOptions overwrite]]; + return [self setData:data forDocument:document merge:NO]; } - (FIRWriteBatch *)setData:(NSDictionary *)data forDocument:(FIRDocumentReference *)document - options:(FIRSetOptions *)options { + merge:(BOOL)merge { [self verifyNotCommitted]; [self validateReference:document]; - FSTParsedSetData *parsed = options.isMerge ? [self.firestore.dataConverter parsedMergeData:data] - : [self.firestore.dataConverter parsedSetData:data]; + FSTParsedSetData *parsed = merge ? [self.firestore.dataConverter parsedMergeData:data] + : [self.firestore.dataConverter parsedSetData:data]; [self.mutations addObjectsFromArray:[parsed mutationsWithKey:document.key precondition:Precondition::None()]]; return self; diff --git a/Firestore/Source/API/FSTUserDataConverter.h b/Firestore/Source/API/FSTUserDataConverter.h index ea20b3e..98a65ae 100644 --- a/Firestore/Source/API/FSTUserDataConverter.h +++ b/Firestore/Source/API/FSTUserDataConverter.h @@ -24,7 +24,6 @@ #include "Firestore/core/src/firebase/firestore/model/field_transform.h" #include "Firestore/core/src/firebase/firestore/model/precondition.h" -@class FIRSetOptions; @class FSTObjectValue; @class FSTFieldValue; @class FSTMutation; @@ -130,7 +129,7 @@ typedef id _Nullable (^FSTPreConverterBlock)(id _Nullable); /** Parse document data from a non-merge setData call.*/ - (FSTParsedSetData *)parsedSetData:(id)input; -/** Parse document data from a setData call with '[FIRSetOptions merge]'. */ +/** Parse document data from a setData call with `merge:YES`. */ - (FSTParsedSetData *)parsedMergeData:(id)input; /** Parse update data from an updateData call. */ diff --git a/Firestore/Source/API/FSTUserDataConverter.mm b/Firestore/Source/API/FSTUserDataConverter.mm index 90d68d8..719f6f5 100644 --- a/Firestore/Source/API/FSTUserDataConverter.mm +++ b/Firestore/Source/API/FSTUserDataConverter.mm @@ -20,14 +20,13 @@ #include #include +#import "FIRGeoPoint.h" #import "FIRTimestamp.h" -#import "FIRGeoPoint.h" #import "Firestore/Source/API/FIRDocumentReference+Internal.h" #import "Firestore/Source/API/FIRFieldPath+Internal.h" #import "Firestore/Source/API/FIRFieldValue+Internal.h" #import "Firestore/Source/API/FIRFirestore+Internal.h" -#import "Firestore/Source/API/FIRSetOptions+Internal.h" #import "Firestore/Source/Model/FSTFieldValue.h" #import "Firestore/Source/Model/FSTMutation.h" #import "Firestore/Source/Util/FSTAssert.h" @@ -595,7 +594,7 @@ typedef NS_ENUM(NSInteger, FSTUserDataSource) { // We shouldn't encounter delete sentinels for queries or non-merge setData calls. FSTThrowInvalidArgument( @"FieldValue.delete() can only be used with updateData() and setData() with " - @"SetOptions.merge()%@", + @"merge:true%@", [context fieldDescription]); } @@ -748,7 +747,7 @@ typedef NS_ENUM(NSInteger, FSTUserDataSource) { // We shouldn't encounter delete sentinels for queries or non-merge setData calls. FSTThrowInvalidArgument( @"FieldValue.delete() can only be used with updateData() and setData() with " - @"SetOptions.merge()."); + @"merge: true."); } } else if ([input isKindOfClass:[FSTServerTimestampFieldValue class]]) { if (![context isWrite]) { diff --git a/Firestore/Source/Core/FSTTransaction.h b/Firestore/Source/Core/FSTTransaction.h index 581a5fa..ab59bde 100644 --- a/Firestore/Source/Core/FSTTransaction.h +++ b/Firestore/Source/Core/FSTTransaction.h @@ -22,7 +22,6 @@ #include "Firestore/core/src/firebase/firestore/model/document_key.h" -@class FIRSetOptions; @class FSTDatastore; @class FSTMaybeDocument; @class FSTObjectValue; diff --git a/Firestore/Source/Core/FSTTransaction.mm b/Firestore/Source/Core/FSTTransaction.mm index 681f9ca..4aabd5a 100644 --- a/Firestore/Source/Core/FSTTransaction.mm +++ b/Firestore/Source/Core/FSTTransaction.mm @@ -22,7 +22,6 @@ #include #import "FIRFirestoreErrors.h" -#import "FIRSetOptions.h" #import "Firestore/Source/API/FSTUserDataConverter.h" #import "Firestore/Source/Core/FSTSnapshotVersion.h" #import "Firestore/Source/Model/FSTDocument.h" diff --git a/Firestore/Source/Public/FIRDocumentReference.h b/Firestore/Source/Public/FIRDocumentReference.h index dd2d106..e7ba6eb 100644 --- a/Firestore/Source/Public/FIRDocumentReference.h +++ b/Firestore/Source/Public/FIRDocumentReference.h @@ -18,10 +18,9 @@ #import "FIRListenerRegistration.h" -@class FIRFirestore; @class FIRCollectionReference; @class FIRDocumentSnapshot; -@class FIRSetOptions; +@class FIRFirestore; NS_ASSUME_NONNULL_BEGIN @@ -82,14 +81,14 @@ NS_SWIFT_NAME(DocumentReference) /** * Writes to the document referred to by this DocumentReference. If the document does not yet - * exist, it will be created. If you pass `FIRSetOptions`, the provided data will be merged into - * an existing document. + * exist, it will be created. If you pass `merge:YES`, the provided data will be merged into + * any existing document. * * @param documentData An `NSDictionary` that contains the fields and data to write to the * document. - * @param options A `FIRSetOptions` used to configure the set behavior. + * @param merge Whether to merge the provided data into any existing document. */ -- (void)setData:(NSDictionary *)documentData options:(FIRSetOptions *)options; +- (void)setData:(NSDictionary *)documentData merge:(BOOL)merge; /** * Overwrites the document referred to by this `FIRDocumentReference`. If no document exists, it @@ -106,18 +105,18 @@ NS_SWIFT_NAME(DocumentReference) /** * Writes to the document referred to by this DocumentReference. If the document does not yet - * exist, it will be created. If you pass `FIRSetOptions`, the provided data will be merged into - * an existing document. + * exist, it will be created. If you pass `merge:YES`, the provided data will be merged into + * any existing document. * * @param documentData An `NSDictionary` containing the fields that make up the document * to be written. - * @param options A `FIRSetOptions` used to configure the set behavior. + * @param merge Whether to merge the provided data into any existing document. * @param completion A block to execute once the document has been successfully written to the * server. This block will not be called while the client is offline, though local * changes will be visible immediately. */ - (void)setData:(NSDictionary *)documentData - options:(FIRSetOptions *)options + merge:(BOOL)merge completion:(nullable void (^)(NSError *_Nullable error))completion; /** diff --git a/Firestore/Source/Public/FIRSetOptions.h b/Firestore/Source/Public/FIRSetOptions.h deleted file mode 100644 index c865e06..0000000 --- a/Firestore/Source/Public/FIRSetOptions.h +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright 2017 Google - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#import - -NS_ASSUME_NONNULL_BEGIN - -/** - * An options object that configures the behavior of setData() calls. By providing the - * `FIRSetOptions` objects returned by `merge:`, the setData() methods in `FIRDocumentReference`, - * `FIRWriteBatch` and `FIRTransaction` can be configured to perform granular merges instead - * of overwriting the target documents in their entirety. - */ -NS_SWIFT_NAME(SetOptions) -@interface FIRSetOptions : NSObject - -/** */ -- (id)init NS_UNAVAILABLE; -/** - * Changes the behavior of setData() calls to only replace the values specified in its data - * argument. Fields with no corresponding values in the data passed to setData() will remain - * untouched. - * - * @return The created `FIRSetOptions` object - */ -+ (instancetype)merge; - -/** Whether setData() should merge existing data instead of performing an overwrite. */ -@property(nonatomic, readonly, getter=isMerge) BOOL merge; - -@end - -NS_ASSUME_NONNULL_END diff --git a/Firestore/Source/Public/FIRTransaction.h b/Firestore/Source/Public/FIRTransaction.h index 51a6e90..2fa4430 100644 --- a/Firestore/Source/Public/FIRTransaction.h +++ b/Firestore/Source/Public/FIRTransaction.h @@ -20,7 +20,6 @@ NS_ASSUME_NONNULL_BEGIN @class FIRDocumentReference; @class FIRDocumentSnapshot; -@class FIRSetOptions; /** * `FIRTransaction` provides methods to read and write data within a transaction. @@ -50,19 +49,19 @@ NS_SWIFT_NAME(Transaction) /** * Writes to the document referred to by `document`. If the document doesn't yet exist, - * this method creates it and then sets the data. If you pass `FIRSetOptions`, the provided data - * will be merged into an existing document. + * this method creates it and then sets the data. If you pass `merge:YES`, the provided data will be + * merged into any existing document. * * @param data An `NSDictionary` that contains the fields and data to write to the document. * @param document A reference to the document whose data should be overwritten. - * @param options A `FIRSetOptions` used to configure the set behavior. + * @param merge Whether to merge the provided data into any existing document. * @return This `FIRTransaction` instance. Used for chaining method calls. */ // clang-format off - (FIRTransaction *)setData:(NSDictionary *)data forDocument:(FIRDocumentReference *)document - options:(FIRSetOptions *)options - NS_SWIFT_NAME(setData(_:forDocument:options:)); + merge:(BOOL)merge + NS_SWIFT_NAME(setData(_:forDocument:merge:)); // clang-format on /** diff --git a/Firestore/Source/Public/FIRWriteBatch.h b/Firestore/Source/Public/FIRWriteBatch.h index 8ff1bec..1568723 100644 --- a/Firestore/Source/Public/FIRWriteBatch.h +++ b/Firestore/Source/Public/FIRWriteBatch.h @@ -19,7 +19,6 @@ NS_ASSUME_NONNULL_BEGIN @class FIRDocumentReference; -@class FIRSetOptions; /** * A write batch is used to perform multiple writes as a single atomic unit. @@ -53,19 +52,19 @@ NS_SWIFT_NAME(WriteBatch) /** * Writes to the document referred to by `document`. If the document doesn't yet exist, - * this method creates it and then sets the data. If you pass `FIRSetOptions`, the provided data - * will be merged into an existing document. + * this method creates it and then sets the data. If you pass `merge:YES`, the provided data will be + * merged into any existing document. * * @param data An `NSDictionary` that contains the fields and data to write to the document. * @param document A reference to the document whose data should be overwritten. - * @param options A `FIRSetOptions` used to configure the set behavior. + * @param merge Whether to merge the provided data into any existing document. * @return This `FIRWriteBatch` instance. Used for chaining method calls. */ // clang-format off - (FIRWriteBatch *)setData:(NSDictionary *)data forDocument:(FIRDocumentReference *)document - options:(FIRSetOptions *)options - NS_SWIFT_NAME(setData(_:forDocument:options:)); + merge:(BOOL)merge + NS_SWIFT_NAME(setData(_:forDocument:merge:)); // clang-format on /** diff --git a/Firestore/Source/Public/FirebaseFirestore.h b/Firestore/Source/Public/FirebaseFirestore.h index 36f9fb7..127c935 100644 --- a/Firestore/Source/Public/FirebaseFirestore.h +++ b/Firestore/Source/Public/FirebaseFirestore.h @@ -27,7 +27,6 @@ #import "FIRListenerRegistration.h" #import "FIRQuery.h" #import "FIRQuerySnapshot.h" -#import "FIRSetOptions.h" #import "FIRSnapshotMetadata.h" #import "FIRTimestamp.h" #import "FIRTransaction.h" -- cgit v1.2.3