Accessing Nested NSDictionary values in Swift 3.0

2019-08-06 03:02发布

问题:

I have the following data I received from Firebase. I have made my snapshotValue a NSDictionary.

self.ref.child("users").child(facebookID_Firebase as! String).observeSingleEvent(of: .value, with: { (snapshot) in
            let snapshotValue = snapshot.value as? NSDictionary
            print(snapshotValue, "snapshotValue")
            //this line of code doesn't work
            //self.pictureURL = snapshot["picture"]["data"]["url"]
        }) { (error) in
            print(error.localizedDescription)
        }

I tried How do I manipulate nested dictionaries in Swift, e.g. JSON data? , How to access deeply nested dictionaries in Swift , and other solutions yet no luck.

How do I access the url value inside the data key AND the picture key?

I can make another reference in Firebase and get the value, but I'm trying to save another request.