gooberboobbutt gooberboobbutt - 2 months ago 6x
Swift Question

Getting weirdly formatted NSDictionary value

var nsarray:[NSMutableDictionary] = [["object":["uid":["age":"26","gender":"male"]]]]


That is how it looks. I want to get the value "uid", so when it prints it is just "uid". Currently it is printing:



I want to get the "uid" value. Meaning when it prints it is just "uid". "uid" is a placeholder for a unique ID so I won't know what the uid is.

It looks like "object" key contains another dictionary, which has exactly one element. To get the first key, call allKeys to get keys, convert them to Array, and pick the the initial element:

let d = nsarray[0]["object"] as! NSDictionary