iOS初学者在这里。
给定一个具有多对多关系的实体
@class Categories;
@interface Events : NSManagedObject
@property (nonatomic, retain) NSString * title;
@property (nonatomic, retain) NSSet *categories;
@end
@interface Events (CoreDataGeneratedAccessors)
- (void)addCategoriesObject:(Categories *)value;
- (void)removeCategoriesObject:(Categories *)value;
- (void)addCategories:(NSSet *)values;
- (void)removeCategories:(NSSet *)values;
@end
与哪个有关
@interface Categories : NSManagedObject
@property (nonatomic, retain) NSString * name;
@property (nonatomic, retain) NSManagedObject *events;
@end
并有一些 JSON 数据来填充事件表
[{"title": "Test Exhibition", "categories": [{"name": "Exhibitions"}]}, {...}]
我应该如何格式化 JSON 数据以执行类似的操作
// Parse Events JSON
[events enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
...
Events *event = [NSEntityDescription
insertNewObjectForEntityForName:@"Events" inManagedObjectContext:context];
event.title = [obj objectForKey:@"title"];
NSSet *categories = [[[NSSet alloc] init] setByAddingObjectsFromArray:[obj objectForKey:@"categories"]];
NSLog(@"CATS %@", categories);
[event addCategories:categories];
最终让核心数据找到相关的类别(已经添加到数据库中)并将其附加到事件?
此刻我得到
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFDictionary entity]: unrecognized selector sent to instance 0x893a8c0'
任何帮助将不胜感激,谢谢!