FIRDataSnapshot.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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 FIRDatabaseReference;
  19. /**
  20. * A DataSnapshot contains data from a Firebase Database location. Any time
  21. * you read Firebase data, you receive the data as a DataSnapshot.
  22. *
  23. * DataSnapshots are passed to the blocks you attach with
  24. * `observe(_:with:)` or `observeSingleEvent(of:with:)`. They are
  25. * efficiently-generated immutable copies of the data at a Firebase Database
  26. * location. They can't be modified and will never change. To modify data at a
  27. * location, use a DatabaseReference (e.g. with `setValue(_:)`).
  28. */
  29. NS_SWIFT_NAME(DataSnapshot)
  30. @interface FIRDataSnapshot : NSObject
  31. #pragma mark - Navigating and inspecting a snapshot
  32. /**
  33. * Gets a DataSnapshot for the location at the specified relative path.
  34. * The relative path can either be a simple child key (e.g. 'fred')
  35. * or a deeper slash-separated path (e.g. 'fred/name/first'). If the child
  36. * location has no data, an empty DataSnapshot is returned.
  37. *
  38. * @param childPathString A relative path to the location of child data.
  39. * @return The DataSnapshot for the child location.
  40. */
  41. - (FIRDataSnapshot *)childSnapshotForPath:(NSString *)childPathString;
  42. /**
  43. * Return true if the specified child exists.
  44. *
  45. * @param childPathString A relative path to the location of a potential child.
  46. * @return true if data exists at the specified childPathString, else false.
  47. */
  48. - (BOOL)hasChild:(NSString *)childPathString;
  49. /**
  50. * Return true if the DataSnapshot has any children.
  51. *
  52. * @return true if this snapshot has any children, else false.
  53. */
  54. - (BOOL)hasChildren;
  55. /**
  56. * Return true if the DataSnapshot contains a non-null value.
  57. *
  58. * @return true if this snapshot contains a non-null value, else false.
  59. */
  60. - (BOOL)exists;
  61. #pragma mark - Data export
  62. /**
  63. * Returns the raw value at this location, coupled with any metadata, such as
  64. * priority.
  65. *
  66. * Priorities, where they exist, are accessible under the ".priority" key in
  67. * instances of NSDictionary. For leaf locations with priorities, the value will
  68. * be under the ".value" key.
  69. */
  70. - (id _Nullable)valueInExportFormat;
  71. #pragma mark - Properties
  72. /**
  73. * Returns the contents of this data snapshot as native types.
  74. *
  75. * Data types returned:
  76. * + `Dictionary`
  77. * + `Array`
  78. * + `NSNumber`-bridgeable types, including `Bool`
  79. * + `String`
  80. *
  81. * @return The data as a native object.
  82. */
  83. @property(strong, readonly, nonatomic, nullable) id value;
  84. /**
  85. * Gets the number of children for this DataSnapshot.
  86. *
  87. * @return An integer indicating the number of children.
  88. */
  89. @property(readonly, nonatomic) NSUInteger childrenCount;
  90. /**
  91. * Gets a DatabaseReference for the location that this data came from.
  92. *
  93. * @return A DatabaseReference instance for the location of this data.
  94. */
  95. @property(nonatomic, readonly, strong) FIRDatabaseReference *ref;
  96. /**
  97. * The key of the location that generated this DataSnapshot.
  98. *
  99. * @return A `String` containing the key for the location of this
  100. * DataSnapshot.
  101. */
  102. @property(strong, readonly, nonatomic) NSString *key;
  103. /**
  104. * An iterator for snapshots of the child nodes in this snapshot.
  105. *
  106. * ```
  107. * for var child in snapshot.children {
  108. * // ...
  109. * }
  110. * ```
  111. *
  112. * @return An NSEnumerator of the children.
  113. */
  114. @property(strong, readonly, nonatomic)
  115. NSEnumerator<FIRDataSnapshot *> *children;
  116. /**
  117. * The priority of the data in this DataSnapshot.
  118. *
  119. * @return The priority as a `String`, or `nil` if no priority was set.
  120. */
  121. @property(strong, readonly, nonatomic, nullable) id priority;
  122. @end
  123. NS_ASSUME_NONNULL_END