У меня есть фрагмент кода, который выполняет обновление базы данных coredata, и я хотел бы знать, когда этот блок будет завершен.Есть ли способ узнать, когда coredata закончила обновлять таблицы?
Основная функция:
NSMutableArray* responseArray = [NSJSONSerialization JSONObjectWithData:data options:0 error:NULL];
dispatch_async(dispatch_get_main_queue(), ^{
[self parseAndAddLovAll:responseArray toArray:self.objects];
});
Функция, используемая в диспетчере:
- (void)parseAndAddLovAll:(NSMutableArray*)responseArray toArray:(NSMutableArray*)destinationArray
{
NSError *error;
DB_ListOfValue_manage *elements_to_store = [[DB_ListOfValue_manage alloc] init];
NSManagedObjectContext * context = [elements_to_store managedObjectContext];
for (int index=0; index < [responseArray count]; index++)
{
NSDictionary * responseArray2 = [[NSDictionary alloc] initWithDictionary:responseArray[index]];
NSString * table_to_store = [[NSString alloc] initWithString:[responseArray2 objectForKey:@"table"]];
NSArray * lignes = [[NSArray alloc] initWithObjects:[responseArray2 objectForKey:@"lignes"], nil];
id value;
// Check if LOV table or contact table
if ((([@"Table_contact" compare:table_to_store])!=NSOrderedSame)&&
(([@"Table_event" compare:table_to_store])!=NSOrderedSame))
{
for (NSDictionary * item in lignes[0])
{
value = [item objectForKey:@"codeevent"];
if ([value isEqualToNumber:[NSNumber numberWithInt:EVENT_ID]])
{//FIXME: bug to check when SYNC
elements_to_store = (DB_ListOfValue_manage*)[NSEntityDescription insertNewObjectForEntityForName:table_to_store inManagedObjectContext:context];
elements_to_store.code_event = [value isKindOfClass:[NSNull class]] ? @"" : value;
value = [item objectForKey:@"id"];
elements_to_store.id = [value isKindOfClass:[NSNull class]] ? @"" : value;
value = [item objectForKey:@"used"];
elements_to_store.used = [value isKindOfClass:[NSNull class]] ? @"" : value;
if (![context save:&error]) {
#ifdef DEBUG
NSLog(@"Whoops, couldn't save: %@", [error localizedDescription]);
#endif
}
else{
#ifdef DEBUG
NSLog(@"Data saved to DB, table %@ %@ %@", table_to_store, elements_to_store.label1, elements_to_store.label2);
#endif
}
}
}
}
}
}