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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T01:05:12+00:00 2026-06-13T01:05:12+00:00

In my iOS application I want to define two block types that take each

  • 0

In my iOS application I want to define two block types that take each other as parameters:

typedef void (^BlockA)(BlockB b);
typedef void (^BlockB)(BlockA a);

This fails compilation with ‘Unknown type name BlockB in the first typedef (that makes sense).

I have a workaround which defines the types like this:

typedef void (^BlockA)(id);
typedef void (^BlockB)(BlockA a);

I then cast back to the BlockB type inside the BlockA definition, but at the expense of type safety.

I also looked at not using typedefs, but this results in an infinite nesting of expanded block definitions.

I know how to resolve circular dependencies for structs with forward declarations, but I can’t see how to do this with blocks.

If there is no solution to the circular dependency, is there a way that I can restrict the parameter to BlockA to be any Block type rather than the generic id, this would give some level of type safety.

  • 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-13T01:05:13+00:00Added an answer on June 13, 2026 at 1:05 am

    typedef does not define a “real” type. It’s basically like a macro that expands out everywhere it’s used. That’s why typedefs cannot be recursive.

    Another way to think about it is, typedefs are never necessary — you can always take any piece of code with a typedef, and simply replace every occurrence of it with the underlying type (that’s what the compiler does when you compile), and it will always work and be completely equivalent. Think about it — how would you do it without a typedef? You can’t. So you can’t do it with a typedef either.

    The only ways to do it are: use id as the argument type to erase the type like you’re doing; or, encapsulate the block inside a “real” type like a struct or class. However, if you do it the latter way, you have to explicitly put the block into and extract the block out of the struct or class, which makes the code confusing. Also, struct is dangerous as struct is a scalar C type, and if you need to capture it by a block, it doesn’t automatically memory-manage the objects inside the struct. As for class, defining a wrapping class is very verbose, and using it for this causes the allocation of an extraneous dummy object for every block it wraps.

    In my opinion, using id like you’re using is fine and is the cleanest way. However, keep in mind that if you need to have that block passed as id be captured by another inner block, that you should cast it back to the block type before being captured, as the capturing semantics is different for block and other object types (blocks are copied, whereas other objects are retained). Just casting it back to the block type at the earliest place will work.

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

Sidebar

Related Questions

I want to create a simple desktop admin application for an IOS app that
For an iOS application, I want to parse an HTML file that may contain
I have an ios application that runs on xcode 3.2.6. I want to change
In my iOS application, I want to store some messages that I obtain from
Let's say I want to make an iOS application that is using new notifications
I want to build an iOS application that recognizes patterns in a cup of
I want to count page visits for each page in my ios application .
I want to develop iOS application that is a remote cotrol via bluetooth for
In my ios application i want to store an object's reference. This object can
I want to create an iOS application which consists of Tamil language. I see

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.