Cra*_*aig 5 xcode bundle core-data accessor ios
好的,所以我对iOS仍然很陌生并且对一些事情感到困惑.首先,这是我的实体......

我在数据方面已有的是Fruit(Apple)和Source(Tree).它们都保存在数据库中.
接下来我想添加一个橙色,但与'Tree'有关系.所以这就是我正在使用的:
Fruit *fruit = (Fruit *)[NSEntityDescription insertNewObjectForEntityForName:@"Fruit" inManagedObjectContext:managedObjectContext];
fruit.fruitName = @"Orange";
NSSet *test = [NSSet setWithObject:fruit];
[_source addSourceFruit:test];
NSLog(@"4");
fruit.fruitSource = _source;
Run Code Online (Sandbox Code Playgroud)
(_source是'Tree',我在Source实体上对'Tree'执行了一个获取请求到一个数组,然后使用objectAtIndex:0(Tree)并将它分配给一个指向源实体的点.
data = [managedObjectContext executeFetchRequest:request error:&error];
Source *_source = [data objectAtIndex:0];
Run Code Online (Sandbox Code Playgroud)
和访问方法:
- (void)addSourceFruitObject:(Fruit *)value;
- (void)removeSourceFruitObject:(Fruit *)value;
- (void)addSourceFruit:(NSSet *)values;
- (void)removeSourceFruit:(NSSet *)values;
Run Code Online (Sandbox Code Playgroud)
我找到了一个关于捆绑的答案,但我不完全确定它们.我已经读过这个' 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:
Run Code Online (Sandbox Code Playgroud)
我相信您通过替换sourceFruit集合来混淆核心数据。核心数据保持逆关系。这意味着您只需fruit.fruitSource = _source;对其进行设置即可了解对象如何连接。你可以用它[_source addSourceFruitObject:fruit]; 来代替,但对我来说这似乎不太简洁。
(旁白:避免使用_name局部变量的命名风格是个好主意。使用这种形式作为支持属性的实例变量已经成为一种标准。)
| 归档时间: |
|
| 查看次数: |
3808 次 |
| 最近记录: |