I need a bit of words about this thing, i know, sure there is something that I'm missing here.
Why avatarUsername and userName into the return are nil?, but inside the user.getDocument {} are having a value... what I'm missing there?
func userData(uID: String) -> (avatar: String, username: String){
let user = db.collection("users").document(uID)
var userName : String!
var avatarUsername : String!
user.getDocument {(document, error) in
if let document = document, document.exists {
guard let avatar = document.data()!["avatar"] else{
return
}
avatarUsername = (avatar as? String)!
guard let username = document.data()!["username"] else{
return
}
userName = (username as? String)!
}
//print("username \(String(describing: userName!))")
}
//print("username \(String(describing: userName!))")
return (avatarUsername,userName)
}
Thanks!