FIRDocumentSnapshot.h 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  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. @class FIRDocumentReference;
  18. @class FIRSnapshotMetadata;
  19. NS_ASSUME_NONNULL_BEGIN
  20. /**
  21. * Controls the return value for server timestamps that have not yet been set to
  22. * their final value.
  23. */
  24. typedef NS_ENUM(NSInteger, FIRServerTimestampBehavior) {
  25. /**
  26. * Return `NSNull` for `FieldValue.serverTimestamp()` fields that have not yet
  27. * been set to their final value.
  28. */
  29. FIRServerTimestampBehaviorNone,
  30. /**
  31. * Return a local estimates for `FieldValue.serverTimestamp()`
  32. * fields that have not yet been set to their final value. This estimate will
  33. * likely differ from the final value and may cause these pending values to
  34. * change once the server result becomes available.
  35. */
  36. FIRServerTimestampBehaviorEstimate,
  37. /**
  38. * Return the previous value for `FieldValue.serverTimestamp()` fields that
  39. * have not yet been set to their final value.
  40. */
  41. FIRServerTimestampBehaviorPrevious
  42. } NS_SWIFT_NAME(ServerTimestampBehavior);
  43. /**
  44. * A `DocumentSnapshot` contains data read from a document in your Firestore database. The data
  45. * can be extracted with the `data` property or by using subscript syntax to access a specific
  46. * field.
  47. *
  48. * For a `DocumentSnapshot` that points to a non-existing document, any data access will return
  49. * `nil`. You can use the `exists` property to explicitly verify a documents existence.
  50. */
  51. NS_SWIFT_NAME(DocumentSnapshot)
  52. @interface FIRDocumentSnapshot : NSObject
  53. /** :nodoc: */
  54. - (instancetype)init
  55. __attribute__((unavailable("FIRDocumentSnapshot cannot be created directly.")));
  56. /** True if the document exists. */
  57. @property(nonatomic, assign, readonly) BOOL exists;
  58. /** A `DocumentReference` to the document location. */
  59. @property(nonatomic, strong, readonly) FIRDocumentReference *reference;
  60. /** The ID of the document for which this `DocumentSnapshot` contains data. */
  61. @property(nonatomic, copy, readonly) NSString *documentID;
  62. /** Metadata about this snapshot concerning its source and if it has local modifications. */
  63. @property(nonatomic, strong, readonly) FIRSnapshotMetadata *metadata;
  64. /**
  65. * Retrieves all fields in the document as a `Dictionary`. Returns `nil` if the document doesn't
  66. * exist.
  67. *
  68. * Server-provided timestamps that have not yet been set to their final value will be returned as
  69. * `NSNull`. You can use the `data(with:)` method to configure this behavior.
  70. *
  71. * @return A `Dictionary` containing all fields in the document or `nil` if the document doesn't
  72. * exist.
  73. */
  74. - (nullable NSDictionary<NSString *, id> *)data;
  75. /**
  76. * Retrieves all fields in the document as a `Dictionary`. Returns `nil` if the document doesn't
  77. * exist.
  78. *
  79. * @param serverTimestampBehavior Configures how server timestamps that have not yet been set to
  80. * their final value are returned from the snapshot.
  81. * @return A `Dictionary` containing all fields in the document or `nil` if the document doesn't
  82. * exist.
  83. */
  84. - (nullable NSDictionary<NSString *, id> *)dataWithServerTimestampBehavior:
  85. (FIRServerTimestampBehavior)serverTimestampBehavior;
  86. /**
  87. * Retrieves a specific field from the document. Returns `nil` if the document or the field doesn't
  88. * exist.
  89. *
  90. * The timestamps that have not yet been set to their final value will be returned as `NSNull`. You
  91. * can use `get(_:serverTimestampBehavior:)` to configure this behavior.
  92. *
  93. * @param field The field to retrieve.
  94. * @return The value contained in the field or `nil` if the document or field doesn't exist.
  95. */
  96. - (nullable id)valueForField:(id)field NS_SWIFT_NAME(get(_:));
  97. /**
  98. * Retrieves a specific field from the document. Returns `nil` if the document or the field doesn't
  99. * exist.
  100. *
  101. * The timestamps that have not yet been set to their final value will be returned as `NSNull`. You
  102. * can use `get(_:serverTimestampBehavior:)` to configure this behavior.
  103. *
  104. * @param field The field to retrieve.
  105. * @param serverTimestampBehavior Configures how server timestamps that have not yet been set to
  106. * their final value are returned from the snapshot.
  107. * @return The value contained in the field or `nil` if the document or field doesn't exist.
  108. */
  109. // clang-format off
  110. - (nullable id)valueForField:(id)field
  111. serverTimestampBehavior:(FIRServerTimestampBehavior)serverTimestampBehavior
  112. NS_SWIFT_NAME(get(_:serverTimestampBehavior:));
  113. // clang-format on
  114. /**
  115. * Retrieves a specific field from the document.
  116. *
  117. * @param key The field to retrieve.
  118. *
  119. * @return The value contained in the field or `nil` if the document or field doesn't exist.
  120. */
  121. - (nullable id)objectForKeyedSubscript:(id)key;
  122. @end
  123. /**
  124. * A `QueryDocumentSnapshot` contains data read from a document in your Firestore database as
  125. * part of a query. The document is guaranteed to exist and its data can be extracted with the
  126. * `data` property or by using subscript syntax to access a specific field.
  127. *
  128. * A `QueryDocumentSnapshot` offers the same API surface as a `DocumentSnapshot`. As
  129. * deleted documents are not returned from queries, its `exists` property will always be true and
  130. * `data()` will never return `nil`.
  131. */
  132. NS_SWIFT_NAME(QueryDocumentSnapshot)
  133. @interface FIRQueryDocumentSnapshot : FIRDocumentSnapshot
  134. /** :nodoc: */
  135. - (instancetype)init
  136. __attribute__((unavailable("FIRQueryDocumentSnapshot cannot be created directly.")));
  137. /**
  138. * Retrieves all fields in the document as a `Dictionary`.
  139. *
  140. * Server-provided timestamps that have not yet been set to their final value will be returned as
  141. * `NSNull`. You can use the `data(with:)` method to configure this behavior.
  142. *
  143. * @return A `Dictionary` containing all fields in the document.
  144. */
  145. - (NSDictionary<NSString *, id> *)data;
  146. /**
  147. * Retrieves all fields in the document as a `Dictionary`.
  148. *
  149. * @param serverTimestampBehavior Configures how server timestamps that have not yet been set to
  150. * their final value are returned from the snapshot.
  151. * @return A `Dictionary` containing all fields in the document.
  152. */
  153. - (NSDictionary<NSString *, id> *)dataWithServerTimestampBehavior:
  154. (FIRServerTimestampBehavior)serverTimestampBehavior;
  155. @end
  156. NS_ASSUME_NONNULL_END