-1

What kind of object is the output of firebase data? Here is the code to output it (from documentation):

myRootRef.observeEventType(.Value, withBlock: {
  snapshot in
  println("\(snapshot.value)")
})

Here is the output:

{
    a =     {
        FirstName = "";
        LastName = "";
    };
    b =     {
        FirstName = "";
        LastName = "";
    };
    c =     {
        FirstName = "";
        LastName = "";
    };
}

What object is that? (Array, Dictionary, String?)

Horay
  • 1,388
  • 2
  • 19
  • 36

2 Answers2

1

It is a Dictionary of type [String: AnyObject]

UPDATE to comment

It is a Dictionary with Key of Type String, which values are Dictionarys with key String and Value String.... So to be exactly

[String: [String: String]]
Dennis Weidmann
  • 1,942
  • 1
  • 14
  • 16
  • Is it nested? because there are 4 diff things. 1: 'a' 2: 'FirstName = ""'; 3: 'LastName = "";' – Horay Aug 26 '15 at 19:24
1

It's an FDataSnapshot. Since Firebase is a NoSQL/JSON data store, it serializes these snapshots to a pseudo-JSON structure when you print them. But when you need to get primitive values out of a snapshot, use the methods of FDataSnapshot like childSnapshotForPath: until you reach a simple property (FirstName and LastName in your sample) and then value to get the primitive value.

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
  • Thanks for the answer! How would I iterate through the data with a for loop? – Horay Aug 27 '15 at 00:37
  • https://www.firebase.com/docs/ios-api/Classes/FDataSnapshot.html#//api/name/children, http://stackoverflow.com/questions/27341888/iterate-over-snapshot-children-in-swift-firebase and the last example here: https://www.firebase.com/docs/ios/guide/structuring-data.html#section-indices – Frank van Puffelen Aug 27 '15 at 01:50
  • Thanks! I tried this answer: http://stackoverflow.com/questions/27341888/iterate-over-snapshot-children-in-swift-firebase#answer-27342233. When I output it to the console, this is what I get: { FirstName = ""; LastName = ""; }; How can I get "FirstName" as a string – Horay Aug 27 '15 at 03:49
  • `snapshot.childSnapshotForPath("FirstName").value` – Frank van Puffelen Aug 27 '15 at 10:41