"[something copyWithZone:]: unrecognized selector sent to instance" when using Bindings / Core Data

Viewed 16307

(self asking and self-answering because I spent hours on the web looking for this, and most of the resources all say "I solved it in the end" without giving an explanation)

I had a very simple Core Data + Bindings application:

  • An NSArrayController pulling items out of Core Data
  • An NSTableView rendering them
  • Another NSTableView that when you click on a row in the first table, displays the details of that item

Item 3 above was causing application crash, with the error:

[(my NSManagedObject) copyWithZone:]: unrecognized selector sent to instance

Implementing that method (!) and putting a breakpoint there, I found it was being invoked by Apple's NSCell class - this didn't much help :(.

9 Answers

Thank you for this solution, it pointed me in the right direction. For those of you learning InterfaceBuilder I hope this additional information helps.

It turns out while building a tutorial I had inadvertently Bound a Text field Cell - Text Cell to my ArrayController.ObjectValue.
The real binding was supposed to happen at

Table Column > Table Cell View > Static Text - Table View Cell

That one was correct, but visually in the tree below it (for reasons I don't understand yet IB needs a Text Field Cell.) I had also bound:

Table Column > Text Field Cell - Text Cell

It was that second binding which trying to copy the whole object because the path was objectValue with no key, it was triggering this error.

Probably a newbie mistake, but it meant walking through EVERY object and checking for bindings and I came across this one.

In general: Check if you are using a @objc function (selector) that passes custom parameters than the default ones

Related