我创建一个核心数据应用程序,其中:当存储在核心数据中时,是否必须存储两个实体数据?
category
实体具有以下属性
CATID:整数
catname:字符串
randomrelation:到-many rel to brandom entity
brandom
是另一实体具有属性
CID:类别实体
没有:整数
ARR:整数
我的代码如下
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]);
}
对不起,但我不明白你的问题。你在问什么?你可以解释吗? – svena
我具有两个实体 第一个类别 第二个qrandom ,以qrandom类之间的关系是多对多 ,并从qrandom到类别是一对多 ,我要求那 ,如何存储数据? –