I have the following model:
struct Organization: Codable, Identifiable {
@DocumentID var id: String? <- Identifiable
let ref: DocumentReference <- Reference to the document
let name: String
enum CodingKeys: String, CodingKey {
case name = "Name"
}
}
I need to use the documentRef in my model for references between different databases and different sub collections.
How can I map the ref and make it codable as it isn't a field.
Furthermore do I get the error Unknown attribute 'DocumentID'
Using Firebase SDK: 10.20.0
It goes a little different
In theory you cannot get rid of the
?sinceDocumentIDsaysValueshould beValue?but you can "pre-populate" the field to minimize the chances that it could benil.One; what I consider a very dangerous; workaround would be to use
!. This would eliminate the optional but I don't know if Firebase guarantees that it will never benilon their end. This could introduce a serious bug.