Вы можете попробовать вот так
var username: String? = nil
self.ref.child("users").observeSingleEvent(of: .value, with: { (snapshot) in
if let usersProfile = snapshot.value as? NSDictionary, let userProfile = usersProfile![userID] as? NSDictionary, let name = userProfile!["username"] as? String {
username = name
}
}) { (error) in
print(error.localizedDescription)
}
print(username)