Ios 是否可以创建一个dispatch_async(dipatch_get_main_queue(),^{});当调度块完成时,是否有一个完成的go get?

Ios 是否可以创建一个dispatch_async(dipatch_get_main_queue(),^{});当调度块完成时,是否有一个完成的go get?,ios,objective-c,core-data,dispatch,Ios,Objective C,Core Data,Dispatch,我有一段代码,用于执行数据库的coredata更新,我想知道该块何时完成。有没有办法让它知道coredata何时完成了表的更新 主要功能: NSMutableArray* responseArray = [NSJSONSerialization JSONObjectWithData:data options:0 error:NULL]; dispatch_async(dispatch_get_main_queue(), ^{ [self parseAn

我有一段代码,用于执行数据库的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
                    }
                }


            }
        }

    }
}
-(void)parseandddlovall:(NSMutableArray*)responseArray to array:(NSMutableArray*)destinationArray
{
n错误*错误;
DB_ListOfValue_manage*元素_to_store=[[DB_ListOfValue_manage alloc]init];
NSManagedObjectContext*context=[元素存储managedObjectContext];
对于(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值;
//检查LOV表或联系表是否正确
如果(([@“Table\u contact”比较:Table\u to\u store])!=SensorDeredName)&&
(([@“Table_事件”比较:Table_to_store])!=SensorDeredName)
{
对于(对齐[0]中的NSDictionary*项)
{
值=[ItemObjectForkey:@“codeevent”];
if([值isEqualToNumber:[NSNumber numberWithInt:EVENT\u ID]])
{//FIXME:同步时要检查的错误
元素存储=(DB_ListOfValue_manage*)[N实体描述插入NewObjectForEntityForName:table_存储在托管对象上下文中:上下文];
元素_to _store.code _事件=[value iskindof类:[NSNull类]]?@'':值;
值=[ItemObjectForkey:@“id”];
元素_to _store.id=[value iskindof类:[NSNull类]]?@'':值;
值=[ItemObjectForkey:@“已使用”];
元素_to_store.used=[value iskindof类:[NSNull类]]?@'':值;
如果(![上下文保存:&错误]){
#ifdef调试
NSLog(@“哎哟,无法保存:%@,[error localizedDescription]);
#恩迪夫
}
否则{
#ifdef调试
NSLog(@“数据保存到数据库,表%@%@”,表U到存储,元素到存储.label1,元素到存储.label2);
#恩迪夫
}
}
}
}
}
}

我建议使用NSFetchedResultsController和NSFetchedResultsController委派。也许你想要的是一个调度组和调度组通知