0

stack overflow community. Please don't mark this question as a duplicate as I have seen all the other posts regarding this and have pretty much gone through most of the famous solutions.

Currently, I have some code that allows a user to send messages to a group and also change the group thumbnail and title. However, upon the user doing any of this, my code crashes. I am storing my data in firebase (the data is being successfully uploaded). The problem began when I upgraded from swift 3 to swift 4. Also, this is the specific error I am getting:

libc++abi.dylib: terminating with uncaught exception of type NSException

Here are some solutions/methods I have tried to solve my problem:

  1. I have outruled that this is an outlet problem as the view controller is programmatically created.
  2. I tried adding an exception breakpoint but it didn't show me any specific lines of code for where the crash occurred.
  3. I have also tried cleaning, re-building, and closing Xcode however that doesn't work as well.
  4. I don't think its a problem with uploading data to firebase as I am able to in other parts of my app.
  5. I have also tried scrolling through the threads to get a deeper understanding of where the crash occurs, however that has not been of much help.

Here is a picture of my console output: The main thread ui stuff is entered into the console is not triggered by the crash. The only output triggered by the crash is the error message above.

Here is the code I use to update the collection view:

func observeConversationMessagesWithConversationId(conversationId: String) {
    Database.database().reference().child("conversation-messages").child(conversationId).observe(.childAdded, with: { (snapshot) in
        if let messages = ConversationMessages(snapshot: snapshot) {

            self.conversationMessages.append(messages)

            DispatchQueue.main.async(execute: {
                self.collectionView?.reloadData()

                let indexPath = NSIndexPath(item: self.conversationMessages.count - 1, section: 0)
                self.collectionView?.scrollToItem(at: indexPath as IndexPath, at: .bottom, animated: true)
            })
        }
    }, withCancel: nil)
}

Here is my podfile

enter image description here

Any help would be appreciated. Please note that I would have added some code but I have no clue where the error occurs.

Rohan Vasishth
  • 417
  • 6
  • 19

1 Answers1

0

Since you don't know where the error occurs, it might be a good idea to place a few breakpoints in your code so you can pinpoint the crash. Then it will be a lot easier to fix the error when you know the exact line where it happens.

I had the same crash and it was related to UIVisualEffectView, and specifically with adding a subview to it instead of adding it to its .contentView.

If that is your case too, you can find more details here.

Good luck bug hunting.

budiDino
  • 13,044
  • 8
  • 95
  • 91
  • Well I figured out the error and it begins to work if I turn the objc inference property on. Which I realize is a bad idea so do you have a new suggestion? – Rohan Vasishth Oct 16 '17 at 20:33