【发布时间】:2012-12-10 10:26:41
【问题描述】:
好的,所以我对 iOS 还是很陌生,对一些事情感到困惑。 首先,这是我的实体...
我在数据中已经有了一个水果(苹果)和一个来源(树)。它们都保存在数据库中。
接下来我想添加一个橙色,但与“树”有关系。所以这就是我正在使用的:
Fruit *fruit = (Fruit *)[NSEntityDescription insertNewObjectForEntityForName:@"Fruit" inManagedObjectContext:managedObjectContext];
fruit.fruitName = @"Orange";
NSSet *test = [NSSet setWithObject:fruit];
[_source addSourceFruit:test];
NSLog(@"4");
fruit.fruitSource = _source;
(_source 是“树”,我对 Source 实体上的“Tree”执行了获取请求到一个数组中,然后将 objectAtIndex:0 (Tree) 分配给指向源实体的点。
data = [managedObjectContext executeFetchRequest:request error:&error];
Source *_source = [data objectAtIndex:0];
以及访问器方法:
- (void)addSourceFruitObject:(Fruit *)value;
- (void)removeSourceFruitObject:(Fruit *)value;
- (void)addSourceFruit:(NSSet *)values;
- (void)removeSourceFruit:(NSSet *)values;
我找到了与捆绑包相关的答案,但我并不完全确定它们。 我已经读过这个 'https://developer.apple.com/library/mac/#documentation/CoreFOundation/Conceptual/CFBundles/AboutBundles/AboutBundles.html' 和 'https://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/CoreData/Articles/cdAccessorMethods.html' 但我似乎并没有很好地掌握它。
编辑:错误是
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSSet intersectsSet:]: set argument is not an NSSet'
*** First throw call stack:
【问题讨论】:
标签: ios xcode core-data bundle accessor