I want to put the value I get from the completion handler into Text view as a string, but I get an error. Here is what I try to do:
func final(name: String, completion: @escaping (_ message: String)-> Void){
guard let uid = AuthViewModel.shared.userSession?.uid else {return}
Firestore.firestore().collection("users").document(uid).collection("chats").document(name).collection("messages").whereField("read", isEqualTo: false).getDocuments { (snapshot, _) in
guard let documents = snapshot?.documents.compactMap({ $0.documentID }) else {return}
let unread = documents.count
let unreadString = String(unread)
completion(unreadString)
}
}
Try to put it in a text like so:
Text(model.final(name: name, completion: { (message) in
String(message)
}))
Here is the error I get
Type '()' cannot conform to 'StringProtocol'; only struct/enum/class types can conform to protocols