Closed rayyanmaretan closed 6 years ago
Hi! Thanks for reaching out! Can you give the code you use for decoding, please?
Hi @alickbass Thank you for replying.
The code:
func listen<T: FirestoreDecodable>(to collectionPath: String, result: @escaping ([T]?, Error?) -> ()) {
firestore.collection(collectionPath).addSnapshotListener { (snapshot, error) in
guard let documents = snapshot?.documents, !documents.isEmpty else { return }
let models: [T] = documents.flatMap({
try! FirestoreDecoder().decode(T.self, from: $0.data()!)
})
result(models, error)
}
}
Hi! FirestoreDecodable is only used for GeoPoint, DocumentReference etc. Don’t use it directly, please use Codable instead.
Thank you @alickbass
I got error when trying to decode using FirestoreDecodable.
Could not cast value of type 'Swift.Dictionary<Swift.String, Any>' to 'Project.StructModel'.
The debugger is pointing on Decoder.swift file, line 1234.
else if options.skipFirestoreTypes && (T.self is FirestoreDecodable.Type) { decoded = value as! T }
How to resolve this?