0

I have declared an optional property of type String. In viewDidload, I call a function which performs optional binding on this property:

public var localMsgIdToBeHighlighted: String? = nil

Following is my method:

 private func performInitialBottomScrolling() {
    if let safeLocalMsgId = self.localMsgIdToBeHighlighted, let safeMsgList = self.messageList {
        var index = 0
        var indexPath: IndexPath? = nil
        for msgModel in safeMsgList {
            if msgModel.localMsgId == safeLocalMsgId {
                indexPath = IndexPath(row: index, section: 0)
                break
            }
            index = index + 1
        }
        if let safeIndexPath = indexPath {
            self.tblViewChatLog.scrollToRow(at: safeIndexPath, at: .bottom, animated: false)
            if let cell = self.tblViewChatLog.cellForRow(at: safeIndexPath) {
                cell.setHighlighted(true, animated: true)
            }
        } else {
            self.scrollToBottom(animation: false)
        }
    } else {
        self.scrollToBottom(animation: false)
    }
}

It was working fine but suddenly crashes started occurring in this method: Refer to this screenshot

What can be the reason of this crash?

rmaddy
  • 314,917
  • 42
  • 532
  • 579
Peeyush karnwal
  • 622
  • 7
  • 24
  • Which line causes the crash? What is the complete error message from the crash? – rmaddy May 07 '19 at 05:05
  • "exC_BAD_ACCESS (code=1, address=0x19)": this crash log shows up at the exact same line when I am trying to access my optional property. – Peeyush karnwal May 07 '19 at 05:19
  • Nothing shown in the debug console? One possible reason might be that your code (not shown in this post) is breaking memory. Does your project has any code using pointers or some other _unsafe_ features? Or is your app multi-threaded? – OOPer May 07 '19 at 05:28
  • Nothing in the console. Although I've verified any memory leaks but uncertain about the cause of this issue. And yes App is multithreaded as I have a lot of DB operation and background tasks. – Peeyush karnwal May 07 '19 at 05:38

0 Answers0