Sorry in advance for the long post, but as a beginner I’m really trying to improve at troubleshooting…
I’m stuck on the Checklists app. Everything went well thru Ch 17, and I was able to successfully troubleshoot any crashes or errors. But now, after creating the DataModel and moving the data storage to the model, etc., I’m getting a few different errors and crashes.
I can create a new checklist, but when I tap (click) on a checklist, I get Thread 1: signal SIGABRT, with the following error:
Could not cast value of type '__NSCFNumber' (0x111528208) to 'Checklists.Checklist' (0x10ffc98c0).
I also get this error:
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Storyboard (<UIStoryboard: 0x600000076d00>) doesn't contain a view controller with identifier 'ListDetailViewController'
The “could not cast value” error seems to tell me that I am somehow miscasting my checklist when sending it to a delegate. I should look for a misplaced ? or ! in the perform and prepare(for segue:) functions — right?
The storyboard error tells me I should check the identifier in the ‘Add Checklist’ Table View Controller, but it is there. Did I screw up an object reference by moving things into folders?
I did not get these errors during Chapter 17, so I’m guessing I screwed something up while moving things to the Data Model.
I searched for these errors in these forums, and also in StackOverflow, but my silly brain is not finding a matching issue.
I stared at my code, alongside the reference source, in two separate Xcode windows. I also stared at FileMerge. Strangely, these did not help.
This would seem to indicate that you are, as you said yourself trying to pass a numeric value (or assign a numeric value) where a Checklist item is expected. The easiest way to find the issue might be to set a breakpoint just before the crash, if you know the line where the crash occurs, and then check the values that are assigned in the variable inspector.
If you don’t know where the crash occurs, then start with the code that you know. For example, if you tap on a table row to select it, then the table view delegate’s didSelectRow method should be executed. So, set a breakpoint there and step through the code.
If you are unable to find the issues, you can always post the full project here (or rather, post a link to a ZIP file) and I can take a look at it.
The issue here is probably not the storyboard ID but rather, the class associated with the view controller for that ID. Check if the class for the view controller with the ID you are looking at has the class set to ListDetailViewController since that’s what your code appears to tell iOS to get …
Thanks @fahim! I truly appreciate your support and quick response.
Following your suggestions, I found a mistake that I had previously missed in tableView(:didSelectRowAt:) – where I changed the wrong line to let checklist = indexofSelectedChecklist (instead of let checklist = dataModel.lists[indexPath.row] ). This caused my crash. Second error cleared up once I fixed the first blunder. Everything seems to be working as expected now, even when trying to break the app!