Search code examples
iosswiftfirebaseswift4firebase-storage

Firebase storage imageReference.delete{ (error) in } method crashing my app with "signal SIGABRT"


I'm using:

  • iOS - Swift 4
  • Cocoapods 1.4.0
  • Firebase (5.4.0)
  • FirebaseCore (5.0.5)
  • FirebaseStorage (3.0.0)

When I'm running the attached code, my app crashing with signal SIGABRT error at the AppDelegate class and prints libc++abi.dylib: terminating with uncaught exception of type NSException in the console.

I'v tried to run some debugging and what I found is that the problem occurred in the imageReference.delete{ (error) in } method.

*Note that it didn't enter to the block at all, it failed in the method itself and because of that the image is not deleting from Firebase console when I'm calling to the delete method.

My code:

func deleteImage(for url:String){
    print(url) // https://firebasestorage.googleapis.com/v0/b/my-app.appspot.com/o/itemsImages%2F225121501531684886976.jpg?alt=media&token=token
    let imageReference = Storage.storage().reference(forURL: url)
    imageReference.delete { (error) in // Fails here with: libc++abi.dylib: terminating with uncaught exception of type NSException
        print("completion") // Not getting to this point
        if let error = error{
            print(error)
        }
    }
}

Edit:

After very deep digging I'v understand that my problem is that I'm calling this method via closure at some point of the "events' tree" (I'm calling some function that calling to another function that calling to the delete method from closure) and thats what cause the problem.

Now the question is how can I call it via this closure without make this error? (I can't call it outside of it)


Solution

  • At the end the problem was with the UITableView itself and not with Firebase.

    I didn't update the UITableView's data array correctly and that produced this crashing. I wasn't aware of it because the errors in xCode's console were disabled from some reason (Those answeres helped me to enable it back: #1, #2).

    Hope anyone else that will face with wired error like that (without enabled error logs, of course) will be able to use my unpleasant experience and find the solution faster and easier.