FIRDataSnapshot.h 4.1 KB

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