Re: blocks and id
Re: blocks and id
- Subject: Re: blocks and id
- From: Andreas Grosam <email@hidden>
- Date: Wed, 12 Dec 2012 12:59:33 +0100
On 12.12.2012, at 12:36, email@hidden wrote:
> You could perhaps make this a little less fragile.
>
> typedef void (^MyBlockType)(void);
>
> // we know this is a block
> void (^isaBlock)(void) = ^(void) {};
>
> MyBlockType aBlock = ^(void) {NSLog(@"I am a block");};
>
> id qua = aBlock;
>
> if ([qua isKindOfClass:[isaBlock class]]) {
> ((MyBlockType)qua)();
> }
>
> Jonathan
Unfortunately, this doesn't work if the block `aBlock` has a closure, and because of this becomes a different class, so that ([qua isKindOfClass:[isaBlock class]]) evaluates to `No`.
The easiest way would certainly be a reliable statement that the common base class for all blocks would be `NSBlock` (or something else).
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden