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