swift - 线程 1:FIRESTORE 内部断言失败:文档引用无效。文档引用必须有偶数个段,但 Posts 有 1 个?
问题描述
为什么我在尝试创建 firebase 计数器时不断收到此错误?我从字面上遵循 google firebase docs line for line。这是创建计数器功能
func createCounter(ref: DocumentReference, numShards: Int) {
ref.setData(["numShards": numShards]){ (err) in
for i in 0...numShards {
ref.collection("shards").document(String(i)).setData(["count": 0])
}
}
}
这就是我尝试使用它的方式
Button("In there"){createCounter(ref: ref.document("Posts"), numShards: 0); incrementCounter(ref: ref.document("Posts"), numShards: 0); getCount(ref: ref.document("Posts"))
}
当我有这个时,我也不断收到这个“从初始化程序返回而不初始化所有存储的属性”错误。
struct PostRow: View {
var post: PostModel
@ObservedObject var postData : PostViewModel
let db = Firestore.firestore()
let uid = Auth.auth().currentUser!.uid
let numShards: Int
let count: Int
init(numShards: Int, count: Int) {
self.numShards = numShards
self.count = count
}
解决方案
init(){}
在SwiftUI 视图中使用此代码。
init() {
UINavigationBar.appearance().barTintColor = UIColor.clear
UINavigationBar.appearance().tintColor = .clear
UINavigationBar.appearance().isOpaque = true
}
推荐阅读
- android - 如何重新连接我的 Firebase 实例以便可以读写?
- java - 在 Android Studio 中更改使用 renderManager 的应用程序中的字体
- angular - 根据父组件中的过滤数据刷新子组件中的表格
- java - 使用 1 行代码实例化和初始化对象数组
- javascript - JSON 到 PHP API 没有发生
- jenkins - 在上游作业中添加的两个参数中只有一个在下游作业中起作用
- c++ - 为什么 glm::mat3 和 glm::value_ptr 创造了一个穿越时间和宇宙的黑洞,并且正在破坏我脑海中任何可能的逻辑?
- rust - 如何根据 Rust 结构中的一些底层数据生成迭代器?
- c - 为什么 C 中的填充对分配在堆栈上的变量/结构有效?
- google-app-engine - 查看部署的文件应用引擎标准?