我有一个问题,通过 coredata 获取的数据然后 count 中没有记录。当应用程序第一次运行时,count 的值为零,一旦取出记录,count 的值就等于 no。的记录。现在我想将 count 的值重置为零。需要你的好意建议。
NSFetchRequest *fetchRequest = [NSFetchRequest fetchRequestWithEntityName:@"Article"];
NSUInteger count = [self.managedObjectContext countForFetchRequest:fetchRequest error:&error];
if(count == 0)
{
NSArray *array = [json valueForKey:@"Artikler"];
for(id key in array){
Article *article = [NSEntityDescription insertNewObjectForEntityForName:@"Article" inManagedObjectContext:context];
article.articleId = [NSNumber numberWithInt:[[key valueForKey:@"Id"]intValue]];
if([key valueForKey:@"Name"]== [NSNull null])
article.name = @"Tittel";
else
article.name = [key valueForKey:@"Name"];
}}