@DocumentID Firestore 使用 Swift Codable
@DocumentID Firestore using Swift Codable
编写 Codable 结构时,我们被告知应该使用
@DocumentID var id: String? = UUID().uuidString
但是id和控制台显示的id不一样?
所以我今天找到了解决方案。事实证明,如果您删除
= UUID().uuidString
来自 属性 并将 id 添加到 CodingKey 枚举
enum CodingKeys: String, CodingKey {
case id
然后您可以取回控制台中显示的 ID!
编写 Codable 结构时,我们被告知应该使用
@DocumentID var id: String? = UUID().uuidString
但是id和控制台显示的id不一样?
所以我今天找到了解决方案。事实证明,如果您删除
= UUID().uuidString
来自 属性 并将 id 添加到 CodingKey 枚举
enum CodingKeys: String, CodingKey {
case id
然后您可以取回控制台中显示的 ID!