1

I want one managedobject to contain a mutablearray. The way I do it is to have an NSString like managedobject called CDstring and then my managedObject will have a many to one relationship with that

CDString.h

@class CDParent;

@interface CDString : NSManagedObject

@property (nonatomic, retain) NSString * strString;
@property (nonatomic, retain) CDParent *asCatalogsIDs;

@end

CDParent.h

@interface CDParent : NSManagedObject

@property (nonatomic, retain) NSNumber * intCatalogCount;
@property (nonatomic, retain) NSNumber * intUnreadCatalogCount;
@property (nonatomic, retain) NSString * strCountry;
@property (nonatomic, retain) NSString * strImageURL;
@property (nonatomic, retain) NSString * strParentId;
@property (nonatomic, retain) NSString * strTitle;
@property (nonatomic, retain) NSOrderedSet *arCatalogIDs;
@end

@interface CDParent (CoreDataGeneratedAccessors)

- (void)insertObject:(CDString *)value inArCatalogIDsAtIndex:(NSUInteger)idx;
- (void)removeObjectFromArCatalogIDsAtIndex:(NSUInteger)idx;
- (void)insertArCatalogIDs:(NSArray *)value atIndexes:(NSIndexSet *)indexes;
- (void)removeArCatalogIDsAtIndexes:(NSIndexSet *)indexes;
- (void)replaceObjectInArCatalogIDsAtIndex:(NSUInteger)idx withObject:(CDString *)value;
- (void)replaceArCatalogIDsAtIndexes:(NSIndexSet *)indexes withArCatalogIDs:(NSArray *)values;
- (void)addArCatalogIDsObject:(CDString *)value;
- (void)removeArCatalogIDsObject:(CDString *)value;
- (void)addArCatalogIDs:(NSOrderedSet *)values;
- (void)removeArCatalogIDs:(NSOrderedSet *)values;
@end

Now when I run this code:

(lldb) po catalogIDasCDString
$1 = 0x1e277d40 <CDString: 0x1e277d40> (entity: CDString; id: 0x1e27d830 <x-coredata://448B312F-9280-4CA3-9088-1186A50F252A/CDString/p402> ; data: {
    asCatalogsIDs = nil;
    strString = 519478bcbbe3850420ec005d;
})
(lldb) po pcd
$2 = 0x1e283110 <CDParent: 0x1e283110> (entity: CDParent; id: 0x1e2c63d0 <x-coredata://448B312F-9280-4CA3-9088-1186A50F252A/CDParent/p401> ; data: {
    arCatalogIDs =     (
    );
    intCatalogCount = nil;
    intUnreadCatalogCount = nil;
    strCountry = Indonesia;
    strImageURL = nil;
    strParentId = "7-eleven_id";
    strTitle = "7-Eleven";
})

 (lldb) 

    [pcd addArCatalogIDsObject:catalogIDasCDString];

I got this error:

2013-06-21 11:42:31.816 domainname[567:1803] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSSet intersectsSet:]: set argument is not an NSSet'
*** First throw call stack:
(0x33cc32a3 0x3b96897f 0x33c6545f 0x345b8883 0x34550c4b 0x345b8765 0x33ab8f67 0x1d75ef 0x20c7eb 0x1cecdb 0x1b1fd5 0x1b25d3 0x1ce70f 0x34558d41 0x345505c1 0x345c8be3 0x3bd8011f 0x3bd8e259 0x3bd8e3b9 0x3bdb4a11 0x3bdb48a4)
libc++abi.dylib: terminate called throwing an exception

WHat is the problem?

Doing it like this:

NSMutableOrderedSet * mos =  [pcd mutableOrderedSetValueForKey:NSStringFromSelector(@selector(arCatalogIDs))];
[mos addObject:catalogIDasCDString]; works though

But I thought [pcd addArCatalogIDsObject:catalogIDasCDString]; is equivalent?

user4951
  • 32,206
  • 53
  • 172
  • 282
Septiadi Agus
  • 1,775
  • 3
  • 17
  • 26
  • Why are you using `NSMutableOrderedSet`? We're your class files automatically generated by something? – Wain Jun 21 '13 at 06:36
  • possible duplicate of [Exception thrown in NSOrderedSet generated accessors](http://stackoverflow.com/questions/7385439/exception-thrown-in-nsorderedset-generated-accessors) - it is a well-known bug with the auto-generated accessor methods for mutable *ordered* sets. – Martin R Jun 21 '13 at 06:51
  • ... correction: A well-known bug with the auto-generated accessor methods for *ordered to-many relationships*. – Martin R Jun 21 '13 at 07:03

0 Answers0