1

I have a simple Parent Child relationship. The relationship is ordered. I have created NSManagedObject Subclasses for each entity. When I attempt to add a Child to the Parent's Chilren ordered Set. I receive the follow error: Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSSet intersectsSet:]: set argument is not an NSSet'.

Here is the relevant code:

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
}

This seems very straight forward. I must be missing something very basic because I can't find any answers on the ole internet.

Thanks!

DrFloyd5
  • 13,555
  • 3
  • 25
  • 34
  • 2
    It is a well-known bug in the generated accessor methods for *ordered* relationships. The answers to the "possible duplicate" thread show various workarounds. – Martin R Aug 09 '13 at 21:12

0 Answers0