FIRSetOptions.m 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /*
  2. * Copyright 2017 Google
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #import "Firestore/Source/API/FIRSetOptions+Internal.h"
  17. #import "Firestore/Source/Model/FSTMutation.h"
  18. NS_ASSUME_NONNULL_BEGIN
  19. @implementation FIRSetOptions
  20. - (instancetype)initWithMerge:(BOOL)merge {
  21. if (self = [super init]) {
  22. _merge = merge;
  23. }
  24. return self;
  25. }
  26. + (instancetype)merge {
  27. return [[FIRSetOptions alloc] initWithMerge:YES];
  28. }
  29. - (BOOL)isEqual:(id)other {
  30. if (self == other) {
  31. return YES;
  32. } else if (![other isKindOfClass:[FIRSetOptions class]]) {
  33. return NO;
  34. }
  35. FIRSetOptions *otherOptions = (FIRSetOptions *)other;
  36. return otherOptions.merge != self.merge;
  37. }
  38. - (NSUInteger)hash {
  39. return self.merge ? 1231 : 1237;
  40. }
  41. @end
  42. @implementation FIRSetOptions (Internal)
  43. + (instancetype)overwrite {
  44. static FIRSetOptions *overwriteInstance = nil;
  45. static dispatch_once_t onceToken;
  46. dispatch_once(&onceToken, ^{
  47. overwriteInstance = [[FIRSetOptions alloc] initWithMerge:NO];
  48. });
  49. return overwriteInstance;
  50. }
  51. @end
  52. NS_ASSUME_NONNULL_END