【发布时间】:2011-10-03 00:44:44
【问题描述】:
全部,
我在我的程序中实现了 Core Data 来存储客户信息。我们称每个实体为“CustomerInformation”。每个“CustomerInformation”实体都有三个属性,“count”、“property2”和“property3”,其中 count 是该特定实体的编号标识符。
假设我有三个“CustomerInformation”实体...
CustomerInformation
-count //for example, this would be "1"
-property2
-property3
CustomerInformation
-count //for example, this would be "2"
-property2
-property3
CustomerInformation
-count //for example, this would be "3"
-property2
-property3
当我删除“CustomerInformation”(2) 时,其他两个将继续计数。此时我需要做的是遍历我的所有实体(在本例中为三个)并查看缺失值在哪里(如果我删除了“CustomerInformation”(2),则 2 将是缺失值)。
这是我的想法,但我需要帮助来完成它。注意:for 循环中的 7 是我要存储的最大客户数,不过不要担心那部分
NSFetchRequest *custRequest = [[NSFetchRequest alloc] init];
ProjectAppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
NSManagedObjectContext *custContext = [appDelegate managedObjectContext];
NSEntityDescription *customerInformation = [NSEntityDescription entityForName:@"CustomerInformation"
inManagedObjectContext:custContext];
[custRequest setEntity:customerInformation];
NSError *error;
NSArray *array = [custContext executeFetchRequest:custRequest error:&error];
for (int n=0; n<=7; n++)
{
//here I need it to go through and find the missing 2
}
【问题讨论】: