FIRSnapshotOptions.mm 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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 "FIRDocumentSnapshot.h"
  17. #import "Firestore/Source/API/FIRSnapshotOptions+Internal.h"
  18. #import "Firestore/Source/Util/FSTAssert.h"
  19. NS_ASSUME_NONNULL_BEGIN
  20. @interface FIRSnapshotOptions ()
  21. @property(nonatomic) FSTServerTimestampBehavior serverTimestampBehavior;
  22. @end
  23. @implementation FIRSnapshotOptions
  24. - (instancetype)initWithServerTimestampBehavior:
  25. (FSTServerTimestampBehavior)serverTimestampBehavior {
  26. self = [super init];
  27. if (self) {
  28. _serverTimestampBehavior = serverTimestampBehavior;
  29. }
  30. return self;
  31. }
  32. + (instancetype)defaultOptions {
  33. static FIRSnapshotOptions *sharedInstance = nil;
  34. static dispatch_once_t onceToken;
  35. dispatch_once(&onceToken, ^{
  36. sharedInstance =
  37. [[FIRSnapshotOptions alloc] initWithServerTimestampBehavior:FSTServerTimestampBehaviorNone];
  38. });
  39. return sharedInstance;
  40. }
  41. + (instancetype)serverTimestampBehavior:(FIRServerTimestampBehavior)serverTimestampBehavior {
  42. switch (serverTimestampBehavior) {
  43. case FIRServerTimestampBehaviorEstimate:
  44. return [[FIRSnapshotOptions alloc]
  45. initWithServerTimestampBehavior:FSTServerTimestampBehaviorEstimate];
  46. case FIRServerTimestampBehaviorPrevious:
  47. return [[FIRSnapshotOptions alloc]
  48. initWithServerTimestampBehavior:FSTServerTimestampBehaviorPrevious];
  49. case FIRServerTimestampBehaviorNone:
  50. return [FIRSnapshotOptions defaultOptions];
  51. default:
  52. FSTFail(@"Encountered unknown server timestamp behavior: %d", (int)serverTimestampBehavior);
  53. }
  54. }
  55. @end
  56. NS_ASSUME_NONNULL_END