迅速完成Firebase完成侦听器 [英] Firebase completion listeners in swift

查看:118
本文介绍了迅速完成Firebase完成侦听器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你如何在swift中执行firebase的完成监听器?它表示在文档中有SetValue和UpdateValue的完成监听器,但是没有例子。

解决方案

setValue的完成是在{}块(闭包)内处理。因此,一旦尝试setValue,该块内的代码执行。错误将是零如果没有和快照将被写入的数据。

  let ref = self.myRootRef.child(some_path)
ref.setValue(Hello,withCompletionBlock :$ {
print(oops,an error)
} else {
print(completed)

















$

  root_ref 
some_path:您好



打印完成


How do you execute a completion listener for firebase in swift? It says there are completion listers for SetValue and UpdateValue in the docs but there is no example.

解决方案

The completion of a setValue is handled within the {} block (closure). So once the attempt to setValue is made, the code within that block executes. error will be nil if none and snapshot will be the data that was written.

let ref = self.myRootRef.child("some_path")
    ref.setValue("Hello", withCompletionBlock: { (error, snapshot) in
        if error != nil {
            print("oops, an error")
        } else {
            print("completed")
        }
    })

gives a result of

root_ref
   some_path: Hello

and prints "completed"

这篇关于迅速完成Firebase完成侦听器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆