Мне нужно инкапсулировать ответ от вызовов AFNetworking в моем собственном методе, поскольку я пишу библиотеку. Этот код приближает меня:
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];
}
Однако мне нужно обработать данные объекта json, возвращенные из getPath, перед возвратом в getDevices (). Я пробовал это:
- (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...
}];
}
Но теперь обратного вызова getDevices ()нет. Итак, как мне обработать объект json в getDevices и вернуть блок по завершении? Благодарю за помощь, так как я новичок в блоках.