【发布时间】:2023-03-23 13:56:01
【问题描述】:
我正在将 coredata 集成到我现有的应用程序中,如 http://wiresareobsolete.com/wordpress/2009/12/adding-core-data-existing-iphone-projects/ 中所述。
我在插入数据时遇到问题。我的数据没有插入到以下实体中。
我正在将 coredata 框架导入到编辑类中。
@interface Editorial : NSManagedObject {
NSInteger id;
NSString *type;
}
@property (nonatomic, assign) NSInteger id;
@property (nonatomic, retain) NSString *type;
我在 Editor.m 中写道:
@implementation Editorial
@synthesize id, type;
在我的 .xcmodel 中,Editorial 也是 NSManagedObject 的子类,并具有相应类型的上述变量。
我想我遗漏了一些非常明显的东西。但我不明白。一般在使用coredata时,如果在项目开始时创建,它会自动插入属性,并且它们不在接口中声明,而是用@dynamic合成。但是在后期集成coredata的时候,是不是应该按照coredata为我们创建的方式创建对应的类呢?
编辑:这就是我为编辑对象插入值的方式。
self.managedObjectContext = appDelegate.managedObjectContext;
newEditorial = (Editorial *)[NSEntityDescription
insertNewObjectForEntityForName:@"Editorial"
inManagedObjectContext:self.managedObjectContext];
strTitle = [NSString stringWithFormat:@"%@",[object valueForKey:@"eletitle"]];
[newEditorial setEletitle:[NSString stringWithFormat:@"%@", strTitle]];
[newEditorial setElecompany:[NSString stringWithFormat:@"%@", strTitle]]; // CRASHING HERE
[self saveAction];
另一件事是它在所示行的第二个字符串插入时崩溃。我来了
* 由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:“* -[NSManagedObject setElecompany:]:无法识别的选择器在此行发送到实例 0x4658800”。
NSString *eleCompany 存在于指定的 coredata 实体和类中。 strTitle 也包含字符串,而不是将其分配给 eleTitle 和 eleCompany,它们都是字符串,存在于类和 coredata 实体中。
有人可以帮忙吗?
这真的很紧急。
提前感谢。
【问题讨论】: