Tutorial 2: Error when I try to run my app

I’m on page 205 of the tutorial. However, when i try to run the app, I get an error:

Could not cast value of type ‘_SwiftTypePreservingNSNumber’ (0x11011ea48) to ‘Checklists.Checklist’ (0x10f4f2e70).

the error happens in “override func prepare” in AllListsViewController.swift. Specifically the line:

controller.checklist = sender as! Checklist

When I hover over the line, it seems to be saying that controller.checklist is nil and that’s causing the crash. But I don’t understand why. I’ve tried going through the code to see if I’ve made any typos, but I haven’t been able to find any. Can anyone help? Thanks!

The error is telling you that the sender is not a Checklist, and that in fact it is some kind of number.

Go back to page 158, and find your code where you start the segue. The line begins with

  performSegue(withIdentifier: "ShowChecklist"...

It sounds like you don’t have the sender set as checklist, and maybe have it as indexPath.row or something.

1 Like