从Firebase请求接收值后调用函数

时间:2016-04-26 09:15:53

标签: ios swift firebase firebase-realtime-database

如何从Firebase请求中获取响应? 因此,例如,一旦我有子计数值,就启动一个函数。

    let FAref = Firebase(url: "https://my-app.firebaseio.com/Users/\(uid!)/Data")


    FAref.observeEventType(FEventType.Value, withBlock: { (snapshot) -> Void in


        if snapshot != nil {

            self.count = Int(snapshot.childrenCount)

        }


    }) { (error) -> Void in
        print(error.description)
    }

1 个答案:

答案 0 :(得分:0)

let FAref = Firebase(url: "https://my-app.firebaseio.com/Users/\(uid!)/Data")


    FAref.observeEventType(FEventType.Value, withBlock: { (snapshot) -> Void in


        if snapshot != nil {

            let count = Int(snapshot.childrenCount)

            //Just add the function call after you get the childrenCount
            self.myFunction(count)
        }


    }) { (error) -> Void in
        print(error.description)
    }