MyLocations App crashes error

I’ve been stuck on this for a while now. When I try to pick a category item, my app crashes and gives me a Thread 1 signal: SIGABRT error and prints to the console → I’ve checked the message and i’m having a hard time figuring it out, need help

2016-06-08 16:41:26.179 MyLocation[74717:2321895] *** Assertion failure in -[NSIndexPath row], /BuildRoot/Library/Caches/com.apple.xbs/Sources/UIKit_Sim/UIKit-3512.60.7/UITableViewSupport.m:2821 2016-06-08 16:41:26.181 MyLocation[74717:2321895] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid index path for use with UITableView. Index paths passed to table view must contain exactly two indices specifying the section and row. Please use the category on NSIndexPath in UITableView.h if possible.'

It looks like you created the NSIndexPath using the wrong constructor, probably NSIndexPath(index:).

I’m getting the same error. Have you found a solution? I inserted an exception break point and it’s catching on UITableViewDelegate. I just don’t understand which index path is missing both parameters that the error speaks about. And why? I believe my code matches what’s written in the book.

override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
    if indexPath.row != selectedIndexPath.row {
        
        if let newCell = tableView.cellForRowAtIndexPath(indexPath) {
            newCell.accessoryType = .Checkmark }
        
        if let oldCell = tableView.cellForRowAtIndexPath(selectedIndexPath) {
            oldCell.accessoryType = .None
        }
        
        selectedIndexPath = indexPath
    }
}

What version of the book do you have? There is a mistake in v3 where selectedIndexPath can be nil when the selected category is initially off-screen. But this has been fixed in v4.

If you have v4 of the book, then the only other thing that can be wrong is that in viewDidLoad(), selectedIndexPath is not filled in with a valid index-path object, so it uses the one that it was initialized with when you declared the variable, var selectedIndexPath = NSIndexPath(). However, that is not a valid index-path object. But this should never happen, since viewDidLoad() will find an index-path that is valid.

So double-check your viewDidLoad() code.

I too had this error, turned out I had “Pick Category” instead of “PickCategory” in my segue prepare function.