获取“无法识别的选择器”当尝试在单元测试中使用 Core Data 托管对象 XCode 生成的类时?
当我尝试在单元测试中使用 Core Data 托管对象 XCode 生成的类时,为什么会出现“无法识别的选择器”?
也就是说,在测试用例中,我必须将方法指定为核心数据托管对象的实例(我使用的是 Xcode 4 生成的托管对象)。为了帮助保持测试轻量级,我可以自己创建对象(不使用核心数据框架)。看起来不错,但是当我尝试使用这些属性时,我得到“无法识别的选择器”。
我猜的问题是:
- 为什么我会得到这个“无法识别的选择器”?
- 如何修改我正在做的事情来创建核心数据管理对象的轻量级版本,以用作单元测试中测试方法的输入?
托管对象的代码示例。例如,这里使用属性“title”会触发问题:
@interface WEView : NSManagedObject {
@private
}
@property (nonatomic, retain) NSString * title;
@end
#import "WEView.h"
@implementation WEView
@dynamic title;
@end
Why am I getting "unrecognized selector" when trying to use Core Data managed object XCode generated class in unit test?
That is, in the test case I have to path the method an instanced of a core data managed object (I'm using Xcode 4 generated managed objects). To aid in keeping the test light weight I through I could just create the object myself (not using the core data framework). Seemed OK however when I try to use the properties I get "unrecognized selector".
Question are I guess:
- Why do I get this "unrecognized selector"?
- How can I modify what I'm doing to create a lightweight version of my core data managed object to be used as input to a method under test in a unit test?
Example of code from managed object. Eg here using the property "title" would trigger the issue:
@interface WEView : NSManagedObject {
@private
}
@property (nonatomic, retain) NSString * title;
@end
#import "WEView.h"
@implementation WEView
@dynamic title;
@end
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
@dynamic 预处理器命令告诉编译器将在运行时提供这些方法。托管对象上下文提供了基于从托管对象模型获取的信息的方法。如果没有上下文,类就没有实际的方法,也无法响应选择器。
The
@dynamic
preprocessor command tells the compiler that the methods will be provided at runtime. It is the managed object context that provides the methods based on information taken from the managed object model. Without the context, the class doesn't have the actual method and can't respond to the selector.