Reputation: 97
Being completely new to Firebase/JSON I'm a bit confused as to how I would retrieve 'base' data. 'Base' probably being the completely wrong syntax.
How would I access/print the 'Places' if they don't have a value? When I give 'New York' a value, I can't add a child to it. So I'm confused how I would get that data?
ViewController
var ref: DatabaseReference?
var handle: DatabaseHandle?
override func viewDidLoad() {
super.viewDidLoad()
ref = Database.database().reference()
handle = ref?.child("Places/London/UK/Latitude").observe(.value, with: { (snapshot) in
let item = snapshot.value as? Double
print(item)
})
}
This prints the latitude fine (because it has a value). But what I want is a list of places - ie London, New York & Paris
Upvotes: 0
Views: 42
Reputation: 209
Simple way to get List of your cities.
handle = ref?.child("Places").observe(.value, with: { (snapshot) in
for child in snapshot.children {
let snap = child as! DataSnapshot
let key = snap.key
let value = snap.value
print("key = \(key))
}
})
Upvotes: 2