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 9183007
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T18:41:49+00:00 2026-06-17T18:41:49+00:00

I’m coming from C#/Java/JS to objectiveC and I’m only a couple of days in,

  • 0

I’m coming from C#/Java/JS to objectiveC and I’m only a couple of days in, so go easy on me.

…so I have a method that takes a block as a parameter:

-(void)subToPub: (NSString*)publisherName 
      channelId: (NSString*)channelId 
       callback: (void(^)(NSDictionary*))cb

which I would usually use as follows:

[myObj  subToPub:@"someId" 
       channelId:@"someOtherId" 
        callback:[(^(NSDictionary* msg){
                    NSLog(@"cb2: %@",msg);
                 }) copy]
];

Now, say I have another method with a compatible signature, for instance:

-(void)subscribeHandler:(NSDictionary*)msg{
    NSLog(@"cb2: %@",msg);
}

is it possible to pass this in as the callback to the subToPub method above, or do I need to wrap this method call in a block?

  • 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-17T18:41:50+00:00Added an answer on June 17, 2026 at 6:41 pm

    Logically you need three pieces of information to make a call to the selector described. The object instance, the name of the selector and the dictionary parameter.

    The block you pass accepts only one piece of information when called — the dictionary. Everything else needs to be captured within the block.

    So, logically, the selector can’t be a straight substitution for the block. Besides anything else, where does knowledge of which instance to call it on come from?

    The only way to produce a record of ‘this method on this specific object’ and compact that into a single object is to put it into a block.

    If you have a defined format of method you want to call (in this case, one with a single argument) and know the object implicitly then you might consider passing in a selector (SEL). So e.g.

    [myObj  subToPub:@"someId" 
           channelId:@"someOtherId" 
            callback:@selector(subscribeHandler:)
    ];
    

    … and subsequently, assuming you know the object you want to talk to as obj and have stored the SEL you received as selector:

    [obj performSelector:selector withObject:msg];
    

    If you want to pass more than one argument then you need to start fooling about with NSInvocations; it’s quite ugly and you’ll soon start to appreciate why closures were added to the language.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a small JavaScript validation script that validates inputs based on Regex. I
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have a text area in my form which accepts all possible characters from
I have been unable to fix a problem with Java Unicode and encoding. The
I have thousands of HTML files to process using Groovy/Java and I need to
I have a view passing on information from a database: def serve_article(request, id): served_article
I have a bunch of posts stored in text files formatted in yaml/textile (from
I am currently running into a problem where an element is coming back from
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function

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.