FIRMutableData

@interface FIRMutableData : NSObject

A FIRMutableData instance is populated with data from a Firebase Database location. When you are using runTransactionBlock:, you will be given an instance containing the current data at that location. Your block will be responsible for updating that instance to the data you wish to save at that location, and then returning using [FIRTransactionResult successWithValue:].

To modify the data, set its value property to any of the native types support by Firebase Database:

  • NSNumber (includes BOOL)
  • NSDictionary
  • NSArray
  • NSString
  • nil / NSNull to remove the data

Note that changes made to a child FIRMutableData instance will be visible to the parent.

  • Returns boolean indicating whether this mutable data has children.

    Declaration

    Swift

    func hasChildren() -> Bool

    Objective-C

    - (BOOL)hasChildren;

    Return Value

    YES if this data contains child nodes.

  • Indicates whether this mutable data has a child at the given path.

    Declaration

    Swift

    func hasChild(atPath path: String) -> Bool

    Objective-C

    - (BOOL)hasChildAtPath:(nonnull NSString *)path;

    Parameters

    path

    A path string, consisting either of a single segment, like ‘child’, or multiple segments, 'a/deeper/child’

    Return Value

    YES if this data contains a child at the specified relative path

  • Used to obtain a FIRMutableData instance that encapsulates the data at the given relative path. Note that changes made to the child will be visible to the parent.

    Declaration

    Swift

    func childData(byAppendingPath path: String) -> FIRMutableData

    Objective-C

    - (nonnull FIRMutableData *)childDataByAppendingPath:(nonnull NSString *)path;

    Parameters

    path

    A path string, consisting either of a single segment, like ‘child’, or multiple segments, 'a/deeper/child’

    Return Value

    A FIRMutableData instance containing the data at the given path

  • To modify the data contained by this instance of FIRMutableData, set this to any of the native types supported by Firebase Database:

    • NSNumber (includes BOOL)
    • NSDictionary
    • NSArray
    • NSString
    • nil / NSNull to remove the data

    Note that setting this value will override the priority at this location.

    Declaration

    Swift

    var value: Any? { get set }

    Objective-C

    @property (readwrite, strong, nonatomic, nullable) id value;

    Return Value

    The current data at this location as a native object

  • Set this property to update the priority of the data at this location. Can be set to the following types:

    • NSNumber
    • NSString
    • nil / NSNull to remove the priority

    Declaration

    Swift

    var priority: Any? { get set }

    Objective-C

    @property (readwrite, strong, nonatomic, nullable) id priority;

    Return Value

    The priority of the data at this location

  • Declaration

    Swift

    var childrenCount: UInt { get }

    Objective-C

    @property (readonly, nonatomic) NSUInteger childrenCount;

    Return Value

    The number of child nodes at this location

  • Used to iterate over the children at this location. You can use the native for .. in syntax:

    for (FIRMutableData* child in data.children) { … }

    Note that this enumerator operates on an immutable copy of the child list. So, you can modify the instance during iteration, but the new additions will not be visible until you get a new enumerator.

    Declaration

    Swift

    var children: NSEnumerator { get }

    Objective-C

    @property (readonly, strong, nonatomic) NSEnumerator *_Nonnull children;
  • key

    Declaration

    Swift

    var key: String? { get }

    Objective-C

    @property (readonly, strong, nonatomic, nullable) NSString *key;

    Return Value

    The key name of this node, or nil if it is the top-most location