I'm trying to access the current logged in user's username and store that into a variable.
self.ref.observeSingleEventOfType(.Value, withBlock: { snapshot in
self.currentUser = (snapshot.value.objectForKey("users")?.objectForKey(self.ref.authData.uid)?.objectForKey("username") as! String)
})
print(“self.currentUser”)
But any code before observeSingleEventOfType() will be executed, then any code after that function will be executed. So this will execute the print statement before retrieving the username. Why does that happen and how can I use the result of that snapshot outside of that function?