【发布时间】:2020-01-09 18:54:47
【问题描述】:
我有一组从 Google Firestore “[428024, 4298212]”返回的 SKU 编号。
我已经编写了一个函数,将 SKU 的数组分配给一个变量,但我不知道如何从函数中返回该变量。
let db = Firestore.firestore()
func getItems() -> [Int] {
let userID = Auth.auth().currentUser?.uid ?? "nil"
if (session.session != nil) {
self.data.removeAll()
db.collection("users").document(userID).getDocument { (document, error) in
if let document = document, document.exists {
let itemID = document.get("items") as! Array<Int>
print(itemID as Any)
// Prints "[428024, 4298212]"
return itemID
} else {
print("Document does not exist")
}
}
}
}
我收到错误“在 void 函数中出现意外的非 void 返回值,但我可以看到 SKU 的数组在运行“print(itemID as Any)”行时被返回。
我写的函数有什么错误吗?
【问题讨论】:
-
快速说如果会话为零或文档不存在什么会返回你的函数?
标签: google-cloud-firestore swiftui