Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 嵌套Firebase完井区块_Ios_Swift_Firebase_Google Cloud Firestore_Block - Fatal编程技术网

Ios 嵌套Firebase完井区块

Ios 嵌套Firebase完井区块,ios,swift,firebase,google-cloud-firestore,block,Ios,Swift,Firebase,Google Cloud Firestore,Block,最近,我一直在开发一个应用程序,它需要以下代码: /** Unfriends the user with the specified UID */ func removeFriend(_ userID: String, completion: CompletionHandler? = nil) { CURRENT_USER_FRIENDS_REF.document(userID).delete { (error) in guard error == nil else{

最近,我一直在开发一个应用程序,它需要以下代码:

/** Unfriends the user with the specified UID */
func removeFriend(_ userID: String, completion: CompletionHandler? = nil) {
    CURRENT_USER_FRIENDS_REF.document(userID).delete { (error) in
        guard error == nil else{
            completion?(error)
            return
        }

        self.users.document(userID).collection(NameFile.Firebase.UserDB.friends).document(AppStorage.PersonalInfo.uid).delete(completion: completion)
    }
}

嵌套这些块时会出现问题。如果第一个块成功,但第二个块抛出错误,则会向完成处理程序传递一个错误。然而,在现实中,有一半的进程成功地写入了数据库。是否可以将这两个块作为一个块一起工作,如果发生错误,该块将传递错误。(无需重新构造数据库)

如果有多个写入操作必须调用成功或全部失败,则应使用。两者之间的区别在于您是否需要文档的当前值来确定其新值。如果您不需要任何文档的当前值,请使用批处理写入。如果确实需要文档的当前值,请对所有写入操作使用事务处理。

如果有多个写入操作必须调用success或all fail,则应使用。两者之间的区别在于您是否需要文档的当前值来确定其新值。如果您不需要任何文档的当前值,请使用批处理写入。如果确实需要文档的当前值,请对所有写入操作使用事务