FIRFieldValue.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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 <Foundation/Foundation.h>
  17. NS_ASSUME_NONNULL_BEGIN
  18. @class FIRVectorValue;
  19. /**
  20. * Sentinel values that can be used when writing document fields with `setData()` or `updateData()`.
  21. */
  22. NS_SWIFT_NAME(FieldValue)
  23. @interface FIRFieldValue : NSObject
  24. /** :nodoc: */
  25. - (instancetype)init NS_UNAVAILABLE;
  26. /** Used with `updateData()` to mark a field for deletion. */
  27. // clang-format off
  28. + (instancetype)fieldValueForDelete NS_SWIFT_NAME(delete());
  29. // clang-format on
  30. /**
  31. * Used with `setData()` or `updateData()` to include a server-generated timestamp in the written
  32. * data.
  33. */
  34. + (instancetype)fieldValueForServerTimestamp NS_SWIFT_NAME(serverTimestamp());
  35. /**
  36. * Returns a special value that can be used with `setData()` or `updateData()` that tells the server
  37. * to union the given elements with any array value that already exists on the server. Each
  38. * specified element that doesn't already exist in the array will be added to the end. If the
  39. * field being modified is not already an array it will be overwritten with an array containing
  40. * exactly the specified elements.
  41. *
  42. * @param elements The elements to union into the array.
  43. * @return The `FieldValue` sentinel for use in a call to `setData()` or `updateData()`.
  44. */
  45. + (instancetype)fieldValueForArrayUnion:(NSArray<id> *)elements NS_SWIFT_NAME(arrayUnion(_:));
  46. /**
  47. * Returns a special value that can be used with `setData()` or `updateData()` that tells the server
  48. * to remove the given elements from any array value that already exists on the server. All
  49. * instances of each element specified will be removed from the array. If the field being
  50. * modified is not already an array it will be overwritten with an empty array.
  51. *
  52. * @param elements The elements to remove from the array.
  53. * @return The `FieldValue` sentinel for use in a call to `setData()` or `updateData()`.
  54. */
  55. + (instancetype)fieldValueForArrayRemove:(NSArray<id> *)elements NS_SWIFT_NAME(arrayRemove(_:));
  56. /**
  57. * Returns a special value that can be used with `setData()` or `updateData()` that tells the server
  58. * to increment the field's current value by the given value.
  59. *
  60. * If the current value is an integer or a double, both the current and the given value will be
  61. * interpreted as doubles and all arithmetic will follow IEEE 754 semantics. Otherwise, the
  62. * transformation will set the field to the given value.
  63. *
  64. * @param d The double value to increment by.
  65. * @return The `FieldValue` sentinel for use in a call to `setData()` or `updateData()`.
  66. */
  67. + (instancetype)fieldValueForDoubleIncrement:(double)d NS_SWIFT_NAME(increment(_:));
  68. /**
  69. * Returns a special value that can be used with `setData()` or `updateData()` that tells the server
  70. * to increment the field's current value by the given value.
  71. *
  72. * If the current field value is an integer, possible integer overflows are resolved to LONG_MAX or
  73. * LONG_MIN. If the current field value is a double, both values will be interpreted as doubles and
  74. * the arithmetic will follow IEEE 754 semantics.
  75. *
  76. * If field is not an integer or double, or if the field does not yet exist, the transformation
  77. * will set the field to the given value.
  78. *
  79. * @param l The integer value to increment by.
  80. * @return The `FieldValue` sentinel for use in a call to `setData()` or `updateData()`.
  81. */
  82. + (instancetype)fieldValueForIntegerIncrement:(int64_t)l NS_SWIFT_NAME(increment(_:));
  83. /**
  84. * Creates a new `VectorValue` constructed with a copy of the given array of NSNumbers.
  85. *
  86. * @param array Create a `VectorValue` instance with a copy of this array of NSNumbers.
  87. * @return A new `VectorValue` constructed with a copy of the given array of NSNumbers.
  88. */
  89. + (FIRVectorValue *)vectorWithArray:(NSArray<NSNumber *> *)array NS_REFINED_FOR_SWIFT;
  90. @end
  91. NS_ASSUME_NONNULL_END