开发者社区> 问答> 正文

如何快速地将Firebase查询“包装”到函数?

我是新的iOS环境,我陷入了这样的境地:

在Google搜索之后,我找到了一种在防火墙中进行查询的方法:

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


我还看到了另一个示例,它将查询结果存储在自己的类属性中,但我不希望这样,我希望在另一个快速文件中实现该函数。

谢谢。

展开
收起
游客5akardh5cojhg 2019-12-05 13:05:16 409 0
0 条回答
写回答
取消 提交回答
问答地址:
问答排行榜
最热
最新

相关电子书

更多
fibjs 模块重构从回调到协程--陈垒 立即下载
低代码开发师(初级)实战教程 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载