我有以下型号:
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"
}
}
我需要在模型中使用 documentRef 来在不同数据库和不同子集合之间进行引用。
如何映射引用并使其可编码,因为它不是字段。
此外我还收到错误
Unknown attribute 'DocumentID'
使用 Firebase SDK:10.20.0
有点不一样
struct Organization: Codable, Identifiable {
@DocumentID var ref: DocumentReference? //This will be auto-populated when you fetch/Decode.
var id: String? {
ref?.id
}
let name: String
enum CodingKeys: String, CodingKey {
case name = "Name"
}
}
确保您已导入
FirebaseFirestoreSwift