我需要一些关于这件事的话,我知道,确定我在这里缺少一些东西。
为什么avatarUsername和userName进入返回值为nil ?,但是在user.getDocument {}里面有一个值...我在那里缺少什么?
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)
}
谢谢!