Is there a way to declare an objective-C typedef block whose arguments contain this typedef?

Here's an interesting objective-C guru out there ...

Is there a way to declare an objective-C typedef block containing an argument of that typedef?

typedef BOOL (^SSCellAction) ( UITableViewController* inTVC, SSCellAction inChainedAction );

      

The idea is that I wanted to use a chained action system in the menu that allows for a chain of work / response (usually 1-3 items). On calling the last action, it skips nil for inChainedAction

. Since this seems relatively trivial to imagine, I'll be tainted if I can't figure out how to declare it without llvm saying no. :)

+3


source to share


1 answer


A comment

rmaddy is correct. As in C, a typedef

cannot use itself. Basically, typedef

it doesn't make a real type, but just makes an alias that the compiler expands at compile time. You can always manually deploy everything typedef

in your program yourself (which is sometimes an instructive exercise) so that your program is written without typedef

s. However, recursive typedef

cannot be extended.

Some possible workarounds:



  • Use id

    as parameter type and return to desired type inside the block. This loses type safety.
  • Or use a single element structure type, block. The structure is a real type, so you can use it in its definition. The downside to this is that you explicitly "wrap up" the block to the struct type to pass it, and explicitly expand the struct into a block, referring to the field when you need to call it. This method is type safe.
+1


source







All Articles