FIRDocumentSnapshot.h 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  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_SENDABLE
  52. NS_SWIFT_NAME(DocumentSnapshot)
  53. @interface FIRDocumentSnapshot : NSObject
  54. /** :nodoc: */
  55. - (instancetype)init
  56. __attribute__((unavailable("FIRDocumentSnapshot cannot be created directly.")));
  57. /** True if the document exists. */
  58. @property(nonatomic, assign, readonly) BOOL exists;
  59. /** A `DocumentReference` to the document location. */
  60. @property(nonatomic, strong, readonly) FIRDocumentReference *reference;
  61. /** The ID of the document for which this `DocumentSnapshot` contains data. */
  62. @property(nonatomic, copy, readonly) NSString *documentID;
  63. /** Metadata about this snapshot concerning its source and if it has local modifications. */
  64. @property(nonatomic, strong, readonly) FIRSnapshotMetadata *metadata;
  65. /**
  66. * Retrieves all fields in the document as a `Dictionary`. Returns `nil` if the document doesn't
  67. * exist.
  68. *
  69. * Server-provided timestamps that have not yet been set to their final value will be returned as
  70. * `NSNull`. You can use the `data(with:)` method to configure this behavior.
  71. *
  72. * @return A `Dictionary` containing all fields in the document or `nil` if the document doesn't
  73. * exist.
  74. */
  75. - (nullable NSDictionary<NSString *, id> *)data;
  76. /**
  77. * Retrieves all fields in the document as a `Dictionary`. Returns `nil` if the document doesn't
  78. * exist.
  79. *
  80. * @param serverTimestampBehavior Configures how server timestamps that have not yet been set to
  81. * their final value are returned from the snapshot.
  82. * @return A `Dictionary` containing all fields in the document or `nil` if the document doesn't
  83. * exist.
  84. */
  85. - (nullable NSDictionary<NSString *, id> *)dataWithServerTimestampBehavior:
  86. (FIRServerTimestampBehavior)serverTimestampBehavior;
  87. /**
  88. * Retrieves a specific field from the document. Returns `nil` if the document or the field doesn't
  89. * exist.
  90. *
  91. * The timestamps that have not yet been set to their final value will be returned as `NSNull`. You
  92. * can use `get(_:serverTimestampBehavior:)` to configure this behavior.
  93. *
  94. * @param field The field to retrieve.
  95. * @return The value contained in the field or `nil` if the document or field doesn't exist.
  96. */
  97. - (nullable id)valueForField:(id)field NS_SWIFT_NAME(get(_:));
  98. /**
  99. * Retrieves a specific field from the document. Returns `nil` if the document or the field doesn't
  100. * exist.
  101. *
  102. * The timestamps that have not yet been set to their final value will be returned as `NSNull`. You
  103. * can use `get(_:serverTimestampBehavior:)` to configure this behavior.
  104. *
  105. * @param field The field to retrieve.
  106. * @param serverTimestampBehavior Configures how server timestamps that have not yet been set to
  107. * their final value are returned from the snapshot.
  108. * @return The value contained in the field or `nil` if the document or field doesn't exist.
  109. */
  110. // clang-format off
  111. - (nullable id)valueForField:(id)field
  112. serverTimestampBehavior:(FIRServerTimestampBehavior)serverTimestampBehavior
  113. NS_SWIFT_NAME(get(_:serverTimestampBehavior:));
  114. // clang-format on
  115. /**
  116. * Retrieves a specific field from the document.
  117. *
  118. * @param key The field to retrieve.
  119. *
  120. * @return The value contained in the field or `nil` if the document or field doesn't exist.
  121. */
  122. - (nullable id)objectForKeyedSubscript:(id)key;
  123. @end
  124. /**
  125. * A `QueryDocumentSnapshot` contains data read from a document in your Firestore database as
  126. * part of a query. The document is guaranteed to exist and its data can be extracted with the
  127. * `data` property or by using subscript syntax to access a specific field.
  128. *
  129. * A `QueryDocumentSnapshot` offers the same API surface as a `DocumentSnapshot`. As
  130. * deleted documents are not returned from queries, its `exists` property will always be true and
  131. * `data()` will never return `nil`.
  132. */
  133. NS_SWIFT_NAME(QueryDocumentSnapshot)
  134. @interface FIRQueryDocumentSnapshot : FIRDocumentSnapshot
  135. /** :nodoc: */
  136. - (instancetype)init
  137. __attribute__((unavailable("FIRQueryDocumentSnapshot cannot be created directly.")));
  138. /**
  139. * Retrieves all fields in the document as a `Dictionary`.
  140. *
  141. * Server-provided timestamps that have not yet been set to their final value will be returned as
  142. * `NSNull`. You can use the `data(with:)` method to configure this behavior.
  143. *
  144. * @return A `Dictionary` containing all fields in the document.
  145. */
  146. - (NSDictionary<NSString *, id> *)data;
  147. /**
  148. * Retrieves all fields in the document as a `Dictionary`.
  149. *
  150. * @param serverTimestampBehavior Configures how server timestamps that have not yet been set to
  151. * their final value are returned from the snapshot.
  152. * @return A `Dictionary` containing all fields in the document.
  153. */
  154. - (NSDictionary<NSString *, id> *)dataWithServerTimestampBehavior:
  155. (FIRServerTimestampBehavior)serverTimestampBehavior;
  156. @end
  157. NS_ASSUME_NONNULL_END