Currently getDocuments function do not supports Codable/Decodable protocol ( It is Swift 4 biggest advantage). Currently I need to write wrapper which uses Codable protocols. Below is example (Example: 2) how I did it. Without using Codable/Decodable I would need to pars responses in old way using dictionary manner as shown in example: 1. It is overkill do not use Codable protocol.
My question is what stop Firebase engineers add Codable advantages to SDK?
// Example 1
query.getDocuments(completion: { (snapshot, error) in
// ....
snapshot.documents.forEach({ (document) in
let name = document.data()["name"]
let street = document.data()["street"]
// And so on ...
let model = Person(name: name, street: street)
self.models.append(model)
})
})
// Example 2
class FirestoreFetcher<T> where T: Decodable {
private var models = [T]()
private var modelsSnapshot = [DocumentSnapshot]()
private var query: Query?
func requestUsing(_ query: Query) {
query.getDocuments(completion: { (snapshot, error) in
guard let snapshot = snapshot else {
print("Error fetching snapshot results: \(error!)")
return
}
snapshot.documents.forEach({ (document) in
let result = document.data().convert(T.self)
if let model = result.object {
self.models.append(model)
}
else {
print("Error on converting to generics: \(document.data())")
}
})
self.modelsSnapshot += snapshot.documents
})
}
}
Currently getDocuments function do not supports Codable/Decodable protocol ( It is Swift 4 biggest advantage). Currently I need to write wrapper which uses Codable protocols. Below is example (Example: 2) how I did it. Without using Codable/Decodable I would need to pars responses in old way using dictionary manner as shown in example: 1. It is overkill do not use Codable protocol.
My question is what stop Firebase engineers add Codable advantages to SDK?