1

managedobjectが含まれている必要がありmutablearrayます。私が行う方法は、CDstring と呼ばれるNSStringようなものを用意し、それと多対 1 の関係を持つことです。managedobjectmanagedObject

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同等だと思いましたか?

4

0 に答える 0