FIRMutableData.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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. /**
  19. * A FIRMutableData instance is populated with data from a Firebase Database
  20. * location. When you are using runTransactionBlock:, you will be given an
  21. * instance containing the current data at that location. Your block will be
  22. * responsible for updating that instance to the data you wish to save at that
  23. * location, and then returning using [FIRTransactionResult successWithValue:].
  24. *
  25. * To modify the data, set its value property to any of the native types support
  26. * by Firebase Database:
  27. *
  28. * + NSNumber (includes BOOL)
  29. * + NSDictionary
  30. * + NSArray
  31. * + NSString
  32. * + nil / NSNull to remove the data
  33. *
  34. * Note that changes made to a child FIRMutableData instance will be visible to
  35. * the parent.
  36. */
  37. NS_SWIFT_NAME(MutableData)
  38. @interface FIRMutableData : NSObject
  39. #pragma mark - Inspecting and navigating the data
  40. /**
  41. * Returns boolean indicating whether this mutable data has children.
  42. *
  43. * @return YES if this data contains child nodes.
  44. */
  45. - (BOOL)hasChildren;
  46. /**
  47. * Indicates whether this mutable data has a child at the given path.
  48. *
  49. * @param path A path string, consisting either of a single segment, like
  50. * 'child', or multiple segments, 'a/deeper/child'
  51. * @return YES if this data contains a child at the specified relative path
  52. */
  53. - (BOOL)hasChildAtPath:(NSString *)path;
  54. /**
  55. * Used to obtain a FIRMutableData instance that encapsulates the data at the
  56. * given relative path. Note that changes made to the child will be visible to
  57. * the parent.
  58. *
  59. * @param path A path string, consisting either of a single segment, like
  60. * 'child', or multiple segments, 'a/deeper/child'
  61. * @return A FIRMutableData instance containing the data at the given path
  62. */
  63. - (FIRMutableData *)childDataByAppendingPath:(NSString *)path;
  64. #pragma mark - Properties
  65. /**
  66. * To modify the data contained by this instance of FIRMutableData, set this to
  67. * any of the native types supported by Firebase Database:
  68. *
  69. * + NSNumber (includes BOOL)
  70. * + NSDictionary
  71. * + NSArray
  72. * + NSString
  73. * + nil / NSNull to remove the data
  74. *
  75. * Note that setting this value will override the priority at this location.
  76. *
  77. * @return The current data at this location as a native object
  78. */
  79. @property(strong, nonatomic, nullable) id value;
  80. /**
  81. * Set this property to update the priority of the data at this location. Can be
  82. * set to the following types:
  83. *
  84. * + NSNumber
  85. * + NSString
  86. * + nil / NSNull to remove the priority
  87. *
  88. * @return The priority of the data at this location
  89. */
  90. @property(strong, nonatomic, nullable) id priority;
  91. /**
  92. * @return The number of child nodes at this location
  93. */
  94. @property(readonly, nonatomic) NSUInteger childrenCount;
  95. /**
  96. * Used to iterate over the children at this location. You can use the native
  97. * for .. in syntax:
  98. *
  99. * for (FIRMutableData* child in data.children) {
  100. * ...
  101. * }
  102. *
  103. * Note that this enumerator operates on an immutable copy of the child list.
  104. * So, you can modify the instance during iteration, but the new additions will
  105. * not be visible until you get a new enumerator.
  106. */
  107. @property(readonly, nonatomic, strong) NSEnumerator<FIRMutableData *> *children;
  108. /**
  109. * @return The key name of this node, or nil if it is the top-most location
  110. */
  111. @property(readonly, nonatomic, strong, nullable) NSString *key;
  112. @end
  113. NS_ASSUME_NONNULL_END