Lets say I have some code like this
let ref = Database.database().reference()
let refTwo = Database.database().reference()
func getPosts() {
ref.child("posts").queryOrderedByKey().observeSingleEvent(of: .value, with: { snap in
// get some posts
})
}
func getOtherStuff() {
refTwo.child("child").queryOrderedByKey().observeSingleEvent(of: .value, with: { snap in
// get some other data
})
refTwo.removeAllObservers()
}
And I call getPosts() and getOtherStuff() in viewDidLoad() do I need to use two different references or can I just use one ref for all of my queries?
I know if you have the same ref using .observe in two different locations the data is only returned once. So you wouldn't want to re-use that ref? However, here I am just using .observeSingleEvent so I'm not sure. Additionally, would it matter if they were on the same child?