本文介绍了“[something copyWithZone:]:unrecognized selector sent to instance”当使用绑定/ Core Data时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

(自我询问和自我回答,因为我在网上花了几个小时寻找这个,大多数资源都说我解决了它,而不给出解释)

(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)

我有一个非常简单的Core Data + Bindings应用程序:

I had a very simple Core Data + Bindings application:


  • NSArrayController从Core Data中提取项目

  • 一个NSTableView呈现它们

  • 另一个NSTableView,当您点击第一个表格中的一行时,会显示该项目的详细信息

上面的项目3导致应用程序崩溃,并显示错误:

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

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

)和放置一个断点,我发现它被苹果的NSCell类调用 - 这没有太多帮助:(。

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

推荐答案

p>结果是需要上面所有的触发这一点,XCode允许你在99.9%的情况下做错了,如果不是100%。

Turns out ALL the above are needed to trigger this, and XCode is allowing you to do something that's wrong in 99.9% of situations, if not 100%.


  1. 核心数据对象不能实现copyWithZone: - 这会导致崩溃

  1. Core-Data objects cannot implement copyWithZone: - this causes the crash

使用Bindings填充,它会尝试复制NSArrayController中对象的以呈现每个列

When a tableview is populated using Bindings, it tries to copy the values of the objects in the NSArrayController to render each Column

...如果你未能完全指定列绑定(Xcode允许你一半指定它),那么tableview会尝试在对象上的复制,而不是他们的

...but if you fail to specify the Column binding fully (Xcode allows you to half specify it), then tableview tries the "copy" on the objects instead of their values

我的绑定中的错误:我已经指定表列有一个值:

The bug in my bindings: I had specified that a Table Column had a "value" with:

(这是XCode4自动完成中的一个错误 - 有时当您快速跳过时会删除ModelKeyPath字段)

(this is a bug in XCode4 autocomplete - it will delete the ModelKeyPath field sometimes when you tab away too quickly)

完成键入,例如:

...一切正常。

这篇关于“[something copyWithZone:]:unrecognized selector sent to instance”当使用绑定/ Core Data时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-17 15:34