添加子对象时,为什么我的NSManagedObject会崩溃

时间:2013-08-09 20:55:43

标签: ios objective-c core-data

我有一个简单的父子关系。这种关系是有序的。我为每个实体创建了NSManagedObject子类。当我尝试将一个Child添加到Parent的Chilren命令Set时。我收到以下错误:由于未捕获的异常'NSInvalidArgumentException'而终止应用程序,原因:'*** - [NSSet intersectsSet:]:set参数不是NSSet'。

以下是相关代码:

CDParent.h

@interface CDParent : NSManagedObject
@property (nonatomic, retain) NSOrderedSet *children;
@end

@interface CDParent (CoreDataGeneratedAccessors)
// snip
- (void)addChildrenObject:(CDChild *)value;
// snip
@end

CDChild.h

@class CDParent;

@interface CDChild : NSManagedObject

@property (nonatomic, retain) CDParent *parent;

@end

CDAppDelegate.m

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
     CDParent *parent = [NSEntityDescription insertNewObjectForEntityForName:@"Parent" inManagedObjectContext:self.managedObjectContext];
     CDChild *child = [NSEntityDescription insertNewObjectForEntityForName:@"Child" inManagedObjectContext:self.managedObjectContext];
     [parent addChildrenObject:child]; // <- CRASH

    // SNIP
}

这似乎非常直截了当。我必须遗漏一些非常基本的东西,因为我无法在网上找到任何答案。

谢谢!

0 个答案:

没有答案
相关问题