在新的iOS环境中,我陷入了困境:
在Google中搜索后,我找到了一种在Firestore中进行查询的方法:
db.collection("cities").whereField("capital", isEqualTo: true)
.getDocuments() { (querySnapshot, err) in
if let err = err {
print("Error getting documents: \(err)")
} else {
for document in querySnapshot!.documents {
print("\(document.documentID) => \(document.data())")
}
}
}
这很好用,但现在我想将其“包装”到一个函数中,例如
func getPlayerFromFirebase(email: String) -> Player {
//Do the query in the collection Players where field "email" == email
//Save the query result in a variable (which is a dictionary)
//decode the dictionary into another variable of type Player
//return the Player variable
}
我不知道该怎么做,因为如果我在打印查询结果的行下面放一个返回值,则会出现此错误Unexpected non-void return value in void function
我也看到了另一个将查询结果存储在其自己的class属性中的示例,但我不想那样,我想在另一个swift文件中实现该功能