FIRMutableData.h 4.1 KB

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