Firebase中的Firebase完成侦听器

Sea*_*ook 2 firebase swift firebase-realtime-database

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

Jay*_*Jay 5

setValue的完成在{}块(闭包)内处理.因此,一旦尝试setValue,就会执行该块中的代码.如果没有,则错误将为nil,快照将是写入的数据.

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

给出了结果

root_ref
   some_path: Hello
Run Code Online (Sandbox Code Playgroud)

并打印"已完成"