Property with value nil is having "unreadable data" and causing crash. Swift 4.2 | iOS

48 Views Asked by At

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?

0

There are 0 best solutions below