我正在创建一个核心数据应用程序,其中:
category
实体具有以下属性
猫:int
猫名:字符串
randomrelation :to-many rel 到随机实体
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]);
}