swift - swift 中的 Firebase 完成监听器

标签 swift firebase firebase-realtime-database

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

最佳答案

setValue 的完成在 {} block (闭包)中处理。因此,一旦尝试设置值,该 block 中的代码就会执行。如果没有,错误将为零,快照将是写入的数据。

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

给出结果

root_ref
   some_path: Hello

并打印“完成”

关于swift - swift 中的 Firebase 完成监听器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38179186/

相关文章:

swift - 使用 firebase 连接到 Tableview 的搜索栏

java - E/FirebaseInstanceId : Failed to get FIS auth token

ios - 如何限制 Firebase 上的星星数量?

android - 如何使用 Firebase 服务器时间戳生成创建日期?

android - 在 firebase 中,如何检索推送时自动创建的 uid?

ios - 从 UIViewController 导航到 SwiftUI View

ios - 重定向到 firebase 动态链接不会打开 IOS 应用程序

ios - 一些具有动态高度的表格 View 单元格,其他具有固定高度

ios - Swift 2.0 fatal error : unexpectedly found nil while unwrapping an Optional value (lldb)

swift - SceneKit 错误 : array for material property contents must have 6 elements