I have a custom model in swift and it has a property of type DocumentReference
I'm getting some data from a cloud function and then I'm trying to decode it back to my model.
DocumentReference doesn't conform to Decodable by itself so I'm trying to write an extension for it.
I can not make it work since I keep getting this error:
Initializer requirement 'init(from:)' can only be satisfied by a 'required' initializer in the definition of non-final class 'DocumentReference'
Any idea how to make this work?
My extension:
import Firebase
extension DocumentReference: Decodable {
public convenience init(from decoder: Decoder) throws {
//
}
}
Existing model:
struct Notification: Identifiable, CollectionProtocol, DocumentProtocol {
var id = UUID()
var documentReference: DocumentReference
var receiverID: String
var type: String
var createdAt: Date
var requestReference: DocumentReference?
var request: Request?
init(document: DocumentSnapshot) {
self.documentReference = document.reference
self.requestReference = document["requestReference"] as? DocumentReference ?? Firestore.firestore().document("")
self.receiverID = document["receiverID"] as? String ?? ""
self.type = document["type"] as? String ?? ""
self.createdAt = (document["createdAt"] as? Timestamp)?.dateValue() ?? Date()
}
}