FIRDataSnapshot.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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 FIRDataSnapshot contains data from a Firebase Database location. Any time
  21. * you read Firebase data, you receive the data as a FIRDataSnapshot.
  22. *
  23. * FIRDataSnapshots are passed to the blocks you attach with
  24. * observeEventType:withBlock: or observeSingleEvent:withBlock:. 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 FIRDatabaseReference (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 FIRDataSnapshot 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 FIRDataSnapshot is returned.
  37. *
  38. * @param childPathString A relative path to the location of child data.
  39. * @return The FIRDataSnapshot for the child location.
  40. */
  41. - (FIRDataSnapshot *)childSnapshotForPath:(NSString *)childPathString;
  42. /**
  43. * Return YES if the specified child exists.
  44. *
  45. * @param childPathString A relative path to the location of a potential child.
  46. * @return YES if data exists at the specified childPathString, else NO.
  47. */
  48. - (BOOL)hasChild:(NSString *)childPathString;
  49. /**
  50. * Return YES if the DataSnapshot has any children.
  51. *
  52. * @return YES if this snapshot has any children, else NO.
  53. */
  54. - (BOOL)hasChildren;
  55. /**
  56. * Return YES if the DataSnapshot contains a non-null value.
  57. *
  58. * @return YES if this snapshot contains a non-null value, else NO.
  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. * + NSDictionary
  77. * + NSArray
  78. * + NSNumber (also includes booleans)
  79. * + NSString
  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 FIRDatabaseReference for the location that this data came from.
  92. *
  93. * @return A FIRDatabaseReference 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 FIRDataSnapshot.
  98. *
  99. * @return An NSString containing the key for the location of this
  100. * FIRDataSnapshot.
  101. */
  102. @property(strong, readonly, nonatomic) NSString *key;
  103. /**
  104. * An iterator for snapshots of the child nodes in this snapshot.
  105. * You can use the native for..in syntax:
  106. *
  107. * for (FIRDataSnapshot* child in snapshot.children) {
  108. * ...
  109. * }
  110. *
  111. * @return An NSEnumerator of the children.
  112. */
  113. @property(strong, readonly, nonatomic)
  114. NSEnumerator<FIRDataSnapshot *> *children;
  115. /**
  116. * The priority of the data in this FIRDataSnapshot.
  117. *
  118. * @return The priority as a string, or nil if no priority was set.
  119. */
  120. @property(strong, readonly, nonatomic, nullable) id priority;
  121. @end
  122. NS_ASSUME_NONNULL_END