如何修复错误“无法识别的选择器发送到实例...”?

How can I fix the error " unrecognized selector sent to instance..."?

我试过这个网站的 Xcode 项目。

http://www.touch-code-magazine.com/tutorial-building-advanced-rss-reader-with-ios6/

但是由于错误,我无法获取RSS信息:

-[RSSItem setDescription:]: unrecognized selector sent to instance 0x7f875bd8e010" 

*** Terminating app due to uncaught exception 'NSInvalidArgumentException',
reason: '-[RSSItem setDescription:]: unrecognized selector sent to instance 0x7f875bd8e010

我试图在 RSSItem.h file 中设置断点并调查了这个错误。

但是我没有找到原因...

您正在学习的教程很旧并且基于 iOS 6。 自 iOS 8 起,NSObject 协议(由所有基于 NSObject 的对象继承)具有 defined description 属性 作为 read-only 字符串。不能在子类中重写属性,因此您尝试创建 read/write description 属性 将不起作用。

您应该使用其他 属性 名称,例如 itemDescription 而不是 description

我的猜测是 属性 名称 'description' 与 NSObject 的 'description' read-only 属性 冲突(因此或多或少是保留的Objective-C 中的名称)。检查您的构建日志以获取有关 'description' 属性 的警告。 我建议将此 RSSItem 属性 重命名为其他名称。