我希望一个managedobject
包含mutablearray
。我这样做的方法是让NSString
像managedobject
一样叫CDstring,然后我的managedObject
将与之有多对一的关系
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
现在,当我运行此代码时:
(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];
我收到了这个错误:
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
问题是什么?
这样做:
NSMutableOrderedSet * mos = [pcd mutableOrderedSetValueForKey:NSStringFromSelector(@selector(arCatalogIDs))];
[mos addObject:catalogIDasCDString]; works though
但我想
等同于[pcd addArCatalogIDsObject:catalogIDasCDString]; is
?