XCode:无法识别的选择器发送到实例 [英] XCode: Unrecognized selector sent to instance

查看:90
本文介绍了XCode:无法识别的选择器发送到实例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到以下错误:

-[订购商品]:无法识别的选择器已发送到实例0x6b5f240

"-[Order items]: unrecognized selector sent to instance 0x6b5f240"

我确实有一个名为Order的类,它看起来像这样:

I do have a class called Order, which looks like this:

Order.h

#import <Foundation/Foundation.h>
#import <CoreData/CoreData.h>

@class OrderItem;

@interface Order : NSManagedObject {
@private
}
@property (nonatomic, retain) NSNumber * orderID;
@property (nonatomic, retain) NSDate * date;
@property (nonatomic, retain) NSNumber * orderCode;
@property (nonatomic, retain) NSSet* items;

@end

Order.m

#import "Order.h"
#import "OrderItem.h"


@implementation Order
@dynamic orderID;
@dynamic date;
@dynamic orderCode;
@dynamic items;

...

它不会扩展任何如果我正确阅读的话,有一个项目方法?

It doesn't extend any sort of class which has an "items" method, if I'm reading that correctly?

还有其他原因会导致我出错吗?更令人发疯的是,此项目直接从以前的项目复制而来,并进行了一些较小的编辑。我已经在两个项目中的每个单个类上进行了文本比较,除了我所做的外观更改外没有其他区别。

Is there any other reason I would be getting such an error. To add to the madness, this project is copied directly from a previous project, with some minor edits. I've done text comparisons on every single class in both projects and there are no differences other than the cosmetic changes I've made.

推荐答案

@动态项告诉编译器,您将为提供方法。

@dynamic items tells the compiler that you will be providing the methods for items.

由于该项目在先前的项目中有效,因此它必须在.m文件中的某处具有以下方法:

Since this was working in a previous project, it must have had the following method somewhere in the .m file:

- (NSSet *)items {
    // Appropriate code
}

如果您不想提供自己的自定义吸气剂,则将 @动态项更改为 @synthesize items ,编译器会为您生成一个。

If you do not want to provide your own custom getter like this, then change @dynamic items to @synthesize items and the compiler will generate one for you.

有关更多详细信息,请参见声明的属性部分Apple在此处提供的 Objective-C编程语言的名称: https://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/ObjectiveC/Chapters/ocProperties.html

For more details, see the Declared Properties section of The Objective-C Programming Language provided by Apple here: https://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/ObjectiveC/Chapters/ocProperties.html

编辑

虽然上面的所有内容仍然适用于普通对象(并且可能仍适用于此处),但我只是注意到这是 NSManagedObject 的子类。

在您的旧数据模型中,可能存在一个称为 items 的关系,因此NSManagedObject和 @dynamic 适用于防止编译器警告。

In your old data model there was probably a relationship called items and therefore the appropriate methods were provided by NSManagedObject and @dynamic was appropriate to prevent compiler warnings.

如果在新数据模型中没有名为<$的关系c $ c> items ,则将不会生成方法,这将导致您到达此处的问题。

If in your new data model there is no relationship named items, then the methods will not be generated and it will cause the problem that you are getting here.

这篇关于XCode:无法识别的选择器发送到实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆