Can someone give me an easy way to fix this code?
You already posted the same question a few days ago and told it was solved. What is the new issue ?
For the first error,
let fetchedUser = try snapshot.data(as:User.self)
I searched Firestore doc https://firebase.google.com/docs/firestore/solutions/swift-codable-data-mapping
They show some sample code
private func fetchBook(documentId: String) {
let docRef = db.collection("books").document(documentId)
docRef.getDocument(as: Book.self) { result in
Book is Codable
struct Book: Codable {
@DocumentID var id: String?
var title: String
var numberOfPages: Int
var author: String
}
Have you declared User as Codable ?
See also this post: https://stackoverflow.com/questions/72103380/how-do-i-read-a-users-firestore-map-to-a-swift-dictionary
For the second error, I think it was answered in reply to your previous post.
- remove coder parameter
- or call User with only coder parameter