最近我开发了一个应用程序,需要以下代码:
/** 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)
}
}
问题出现在这些块的嵌套中。如果第一个块成功,但第二个块抛出错误,则将向完成处理程序传递错误。然而,实际上,有一半的过程成功了,并成功地写入了数据库。如果发生错误,是否可以让这两个块作为一个传递错误的块一起工作。(不重组数据库)