Can someone help me fix this code.

Can someone give me an easy way to fix this code?

Answered by Claude31 in 815104022

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
Accepted Answer

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

Thank you I will try this.

Can someone help me fix this code.
 
 
Q