我有这个工作,然后由于某种原因停止了。我有一个列表视图,允许用户编辑或添加新记录。当用户选择添加/编辑时,工作表/模式将弹出打开,他们可以提交更改。它正在刷新主列表视图,但现在停止了。
我正在使用 firebase 来支持列表视图并允许用户编辑/添加记录。我正在使用 dispatch.main.async 来刷新主线程 ui。我错过了什么吗?这不应该工作吗?为什么它会停止工作?
func getData() {
print("fetch data")
// Get a reference to the database
let db = Firestore.firestore()
// Read the documents at a specific path
db.collection("todos").getDocuments { snapshot, error in
// Check for errors
if error == nil {
// No errors
if let snapshot = snapshot {
// Update the list property in the main thread
DispatchQueue.main.async {
// Get all the documents and create Todos
self.list = snapshot.documents.map { d in
// Create a Todo item for each document returned
return Todo(id: d.documentID,
name: d["name"] as? String ?? "",
notes: d["notes"] as? String ?? "",
email: d["email"] as? String ?? "")
}
}
}
}
else {
print("Can't find data.")
}
}
}