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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T12:13:58+00:00 2026-05-22T12:13:58+00:00

I’d like to get rid of the complex type declaration before my one-shot blocks:

  • 0

I’d like to get rid of the complex type declaration before my one-shot blocks:

void (^blockHelperA)(NSString*, NSString*) = ^(NSString *foo, NSString *bar) {…};

This could be rewritten as:

id blockHelperB = ^(NSString *foo, NSString *bar) {…};

Which looks better and compiles, but can’t be directly executed:

// “Called object type 'id' is not a function or function pointer”
blockHelperB(@"Foo", @"Bar");

Then there’s a dispatch_block_t type, but that’s just a simple shorthand:

typedef void (^dispatch_block_t)(void);

Is there a way to get rid of the precise type declaration and still execute the block afterwards in a simple way? I know I can do this:

id foo = ^{ return @"bar"; };
dispatch_sync(dispatch_get_current_queue(), foo);

…but that just shifts the noise from the declaration to execution.

  • 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-05-22T12:13:59+00:00Added an answer on May 22, 2026 at 12:13 pm

    There is no (sane) way to do this as you are restricted by C’s type system.

    For function pointers and blocks in particular, C will not allow you to define a “generic” type.

    An example of this is that the type dispatch_block_t will only work with blocks that have a void return type and zero arguments. No other block signature will work. Period.

    Since blocks are effectively transformed into function pointers at compile time (among other magic), there is no direct type associated with them. Your mileage may vary greatly as to the actual type of block that you have stored in any given block reference. So, with this in mind, you can understand why the compiler doesn’t understand you when you try to store a block in an id.

    More information on this can be found here: http://clang.llvm.org/docs/Block-ABI-Apple.html.

    Sorry, but this is just one of those quirks that you will have to learn to live with.

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

Sidebar

Related Questions

i would like to get rid of the defualt grey bar which apears at
I'm working on an VB6 app and I'd like to get rid of the
I use NSLog in my application. And I'd like to get rid of the
So my string is something like BlaBlaBlaDDDaaa2aaa345 I want to get rid of its
I like (bool) way more, but it generates warnings. How do i get rid
How do I get rid of the whitespace in my application: I would like
We'd like to get rid of NHibernate for something like Massive, PetaPoco, etc. but
I would like to get rid of all the file extensions on my site.
I would like to get rid of the search of id's of certain column
On the site: ukrainiansecret.com I would like to get rid of that green right

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.