swift - FirestoreSwift @DocumentID 无法在 Xcode 11 中编译
问题描述
我FirebaseFirestoreSwift
在我的 Xcode 11 项目中使用该模块,但无法编译以下结构。我得到错误:
属性类型“String”与其包装器类型“DocumentID”的“wrappedValue”属性不匹配
import FirebaseFirestoreSwift
struct CustomerLocation: Codable {
@DocumentID var id: String // <- error is here
let contactEmail: String
let contactName: String
let contactPhoneNumber: String
let serviceContactEmail: String
}
我正在做一个简单的获取和文档解码,如下所示:
func fetchCustomerLocation(path: String) {
firestore.document(path).getDocument{ (document, error) in
guard error == nil, let document = document, document.exists else {
print("Error retrieving customer location document. \(error!.localizedDescription)")
return
}
do {
let result = try document.data(as: CustomerLocation.self)
print(result!)
}
catch let error {
print("Error retrieving parsing location document. \(error.localizedDescription)")
}
}
}
我不希望将 a 传递[String: Any]
给init
.
有任何想法吗?
谢谢
解决方案
@DocumentID
属性包装器确实有一个可选的init
:
public struct DocumentID<Value: DocumentIDWrappable & Codable & Equatable>:
DocumentIDProtocol, Codable, Equatable {
var value: Value?
public init(wrappedValue value: Value?) {
self.value = value
}
...
所以来自sllopis的建议解决了我的问题。谢谢
推荐阅读
- python - SSM 的 BOTO3 服务员类型
- python - 模型方法之和 django
- javascript - d3.js v4 和 v5 的兼容性
- javascript - 计算 DnD 掷骰子应用的平均伤害
- python - 是否有一个虚拟的 Scaler 对插入管道没有任何作用?
- xcode - 在 XCode 中按数字选择编辑器选项卡的键盘快捷键
- python - 想要将列表的元素更改为python中的字典键
- javascript - 退出循环后 ProductArray 保持为空
- ionic-framework - 关于标签与页面的离子路由问题
- python - 如何将 Xarray 图 xr.ufuncs.log(data_slice).plot(cmap='magma', vmin=0, vmax = max_value*.7) 转换为 matplotlib 图?