FIRSetOptions.mm 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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. NS_ASSUME_NONNULL_BEGIN
  18. @implementation FIRSetOptions
  19. - (instancetype)initWithMerge:(BOOL)merge {
  20. if (self = [super init]) {
  21. _merge = merge;
  22. }
  23. return self;
  24. }
  25. + (instancetype)merge {
  26. return [[FIRSetOptions alloc] initWithMerge:YES];
  27. }
  28. - (BOOL)isEqual:(id)other {
  29. if (self == other) {
  30. return YES;
  31. } else if (![other isKindOfClass:[FIRSetOptions class]]) {
  32. return NO;
  33. }
  34. FIRSetOptions *otherOptions = (FIRSetOptions *)other;
  35. return otherOptions.merge == self.merge;
  36. }
  37. - (NSUInteger)hash {
  38. return self.merge ? 1231 : 1237;
  39. }
  40. @end
  41. @implementation FIRSetOptions (Internal)
  42. + (instancetype)overwrite {
  43. static FIRSetOptions *overwriteInstance = nil;
  44. static dispatch_once_t onceToken;
  45. dispatch_once(&onceToken, ^{
  46. overwriteInstance = [[FIRSetOptions alloc] initWithMerge:NO];
  47. });
  48. return overwriteInstance;
  49. }
  50. @end
  51. NS_ASSUME_NONNULL_END