Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8129539
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T08:20:57+00:00 2026-06-06T08:20:57+00:00

I need to encapsulate the response from AFNetworking calls within my own method as

  • 0

I need to encapsulate the response from AFNetworking calls within my own method as I’m writing a library. This code gets me close:

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];
}

However, I need to process the json object data returned from getPath before returning to getDevices().
I’ve tried this:

- (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 ...
   }];
}

But now there is no call back to getDevices().
So how do I process the json object in getDevices & have the block return on completion?
Appreciate the help, as I’m new to blocks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T08:20:59+00:00Added an answer on June 6, 2026 at 8:20 am

    That’s really easy to do: Just invoke the block by calling it like a function.

    - (void)getDevices:(NSString *)netPath 
               success:(void (^)(id  myResults))success
               failure:(void (^)(AFHTTPRequestOperation *operation, NSError *error)) failure
    {
      [[MyApiClient sharedDeviceServiceInstance] 
         getPath:netPath
      parameters:nil
         success:^(AFHTTPRequestOperation *operation, id responseObject)
         {
           id myResults = nil;
           // ... can process json object here ...
           success(myResults);
         }                           
         failure:^(AFHTTPRequestOperation *operation, NSError *error) {
           // ... process errors here ...
           failure(operation, error);
         }];
    }
    

    EDIT:

    Based on the code you posted I think the following interface would be more clear:

    typedef void(^tFailureBlock)(NSError *error);
    
    - (void)getDevicesForUserID:(NSString *)userID 
                        success:(void (^)(NSArray* devices))successBlock
                        failure:(tFailureBlock)failureBlock;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've always been told to encapsulate ANY and ALL properties from a class... This
basically I want to encapsulate a simple component from code that I already have.
I understand delegates encapsulate method calls. However I'm having a hard time understanding their
I need to extend a class, which is encapsulated in a closure. This base
Need to use own imaged markers instead built-in pins. I have several questions. 1.
Need some help to solve this. I have a gridview and inside the gridview
Here is my code: $result = mysql_query(SELECT * FROM Product_Characteristics); $charact_array = array(); while($row
I need to abstract some behavioural code and have a problem trying to reference
I need to encapsulate a set of tables JOINs that we freqently make use
I am creating a gui widget a dll library, a class that derives from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.