Search code examples
iosobjective-ciphonerestkit

Restkit 0.24.1 POST to Server and get response synchronously


does any one know how to receive response of posted array synchronously? here i have:

[manager postObject:objectArray path:@"" parameters:nil success:^(RKObjectRequestOperation *operation, RKMappingResult *result) {
    NSLog(@"Loading mapping result: %@", result.firstObject);
    res = [NSMutableArray arrayWithArray:[result array]];
} failure:^(RKObjectRequestOperation *operation, NSError *error) {
    if (operation.error) {...}

but i want get [result array]; without any delay


Solution

  • If you just want to block current thread

    __block BOOL operationDone = NO;
    [[RKObjectManager sharedManager] getObject:nil
                                          path:path
                                    parameters:parameters
                                       success:^(RKObjectRequestOperation *operation, RKMappingResult *blockMappingResult) {
    
                                               // Do something
    
                                               operationDone = YES;
                                           }
                                       failure:^(RKObjectRequestOperation *operation, NSError *error) {
    
                                               // Do something
    
                                               operationDone = YES;
                                           }];
    
    while(!operationDone) {
        [[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate distantFuture]];
    }