【发布时间】:2012-06-17 05:40:04
【问题描述】:
我正在创建一个核心数据应用程序,其中:
category实体具有以下属性
catid:int
猫名:字符串
随机关系:与品牌实体的多相对关系
brandom 是另一个具有属性的实体
cid:类别实体
否:int
arr:int
我的代码如下
category *c=[NSEntityDescription insertNewObjectForEntityForName:@"category" inManagedObjectContext:context];
for (int i=0; i<[arrayofnumbers count]; i++) {
brandom *r=[NSEntityDescription insertNewObjectForEntityForName:@"brandom" inManagedObjectContext:context];
c.catid=[NSNumber numberWithInt:i];
r.cid=c;
r.no=[NSNumber numberWithInt:i+1];
int objectatindex=[[arrayofnumbers objectAtIndex:i] intValue];
NSLog(@"object at index:%i",objectatindex);
r.arr=[NSNumber numberWithInt:objectatindex];
[set addObject:r];
}
c.randomrelation=r;
NSLog(@"set element count=%i",[set count]);
if (![context save:&error]) {
NSLog(@"%@",[error localizedDescription]);
}
【问题讨论】:
-
对不起,我不明白你的问题。你问的是什么?你能解释一下吗?
-
我有两个实体第一个一个类别第二个 qrandom,类别与 qrandom 之间的关系是多对多,从 qrandom 到类别是一对多,我在问,如何存储数据?
标签: ios xcode cocoa-touch core-data