Recently I have been developing an app which requires the following code:
/** 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)
}
}
The problem arises in nesting these blocks. If the first blocks succeeds, but the second block throws an error, the completion handler will be passed an error. However, in reality, half the process succeeded and wrote successfully to database. Is it possible to have both these blocks work together as one block which passes an error if an error occurs. (without restructuring the database)