【发布时间】:2018-11-08 15:31:00
【问题描述】:
我在一个 iPhone 应用程序 (Swift 4) 上工作,我同时在几个节点上对我的数据库进行一些更新。
以下两种方法都有效,但我想知道最“干净”的方法是什么?
方式一:
let idNotification = BaseViewController.database.child("notifications").childByAutoId().key
BaseViewController.database.child("notifications").child(idNotification).updateChildValues(["content" : "some content"])
BaseViewController.database.child("users").child(userID).child("notifications").updateChildValues(["something" : true])
方式 2:
let idNotification = BaseViewController.database.child("notifications").childByAutoId().key
let createNotif = ["content" : "some content"]
let notifToUser = ["something" : true]
BaseViewController.database.updateChildValues(["/notifications/\(idNotification)" : createNotif, "/users/\(userID)/notifications" : notifToUser])
如果这在崩溃的情况下有什么不同?对于第一个,如果两个更新请求中的一个失败,则另一个不会受到影响。如果仅两者之一失败,方法 2 会发生什么?
谢谢!
【问题讨论】:
标签: ios swift firebase firebase-realtime-database