I'd like to add new func to get info from my firebase about id, name, etc. from my firebase to add it in ProfileView, but the above error will occur. This is what happens when my ProfileView previews and crashes. I do not know why it happens after I wrote new function. Could you tell me how to solve it?
P.S. I apologize in advance for my bad, if I failed to state the problem correctly
func getProfile(completion: @escaping (Result<MWUser, Error>) -> ()) {
PROBLEM IS HERE --> usersRef.document(AuthService.shared.currentUser!.uid).getDocument { docSnapshot, error in
guard let snap = docSnapshot else { return }
guard let data = snap.data() else { return }
guard let userName = data["name"] as? String else { return }
let id = data["id"] as? String ?? ""
guard let phone = data["phone"] as? Int else { return }
guard let address = data["address"] as? String else { return }
guard let company = data["company"] as? String else { return }
let user = MWUser(id: id, name: userName, phone: phone, company: company, address: address)
completion(.success(user))
}
}