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

  • Home
  • SEARCH
  • 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 8117587
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T04:13:21+00:00 2026-06-06T04:13:21+00:00

I have an instance method that I’d like to invoke directly using the callback

  • 0

I have an instance method that I’d like to invoke directly using the callback param from a block in objective-c. I prefer this approach when I need to do more than a simple 1 liner in the callback.

Here is the basic setup…

I init a class w/ some type of call back so I can parse json after the http request lets say

- (void)initFooAndDoStuff {
    Foo *foo = [[Foo alloc] initWithCallback:^(NSData * response){
        // do stuff
    }];
}

//this is the instance method I'd like to invoke instead of an inline function
- (void)callBackWithHttpResponse:(NSData *)response {
    // do stuff ... assuming it's more complex than a 1 liner that is
}

I can setup a call back that does something inline (but again more complex stuff would be better in a stand alone instance method perhaps)

Foo *foo = [[Foo alloc] initWithCallback:^(NSData * response){ 
    NSLog(@"foo"); 
}];

I can use the instance method like below but it feels a little long winded. Any way I can cut this down (the syntax that is).

Foo *foo = [[Foo alloc] initWithCallback:^(NSData * response){ 
    [self callBackWithHttpResponse:response]; 
}];
  • 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-06T04:13:23+00:00Added an answer on June 6, 2026 at 4:13 am

    If you’re going to put the implementation in a method, you might as well just have the method return the entire block:

    -(void (^)(NSData *))httpResponseHandler {
        return ^(NSData *responseData){
            // do something with responseData
        };
    }
    

    Then the places you use it would be a bit more succinct:

    Foo *foo = [[Foo alloc] initWithCallback:[self httpResponseHandler]]; 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a class with an instance method that runs RSpec using the %x[]
I have an IBAction instance method that is connected to a slider, and displays
I have a method that calls a service to retrieve an instance of an
I have a method where I would like to return an object instance of
I'd like to override a method in an Objective C class that I don't
I'd like to override a method in an Objective C class that I don't
I have a UITableView instance tableView that displays data from a server. The tableView
Say I have an instance method that does many different things that I need
I have an UIWebView with my application and want to call Objective-C method from
I have an instance method that populates a vector of strings. I am trying

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.