Note that there are some explanatory texts on larger screens.

plurals
  1. POWrapping success failure blocks from AFNetworking within a method
    text
    copied!<p>I need to encapsulate the response from AFNetworking calls within my own method as I'm writing a library. This code gets me close:</p> <pre><code>MyDevice *devices = [[MyDevice alloc] init]; [devices getDevices:@"devices.json?user_id=10" success:^(AFHTTPRequestOperation *operation, id responseObject) { ... can process json object here ... } - (void)getDevices:(NSString *)netPath success:(void (^)(AFHTTPRequestOperation *operation, id responseObject))success failure:(void (^)(AFHTTPRequestOperation *operation, NSError *error)) failure { [[MyApiClient sharedDeviceServiceInstance] getPath:[NSString stringWithFormat:@"%@", netPath] parameters:nil success:success failure:failure]; } </code></pre> <p>However, I need to process the json object data returned from getPath before returning to getDevices(). I've tried this:</p> <pre><code>- (void)getDevices:(NSString *)netPath success:(void (^)(id myResults))success failure:(void (^)(AFHTTPRequestOperation *operation, NSError *error)) failure { [[MyApiClient sharedDeviceServiceInstance] getPath:[NSString stringWithFormat:@"%@", netPath] parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) { ... can process json object here ... } failure:^(AFHTTPRequestOperation *operation, NSError *error) { ... process errors here ... }]; } </code></pre> <p>But now there is no call back to getDevices(). So how do I process the json object in getDevices &amp; have the block return on completion? Appreciate the help, as I'm new to blocks.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload