• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: blocks and id
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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

References: 
 >blocks and id (From: Andreas Grosam <email@hidden>)
 >Re: blocks and id (From: Charles Srstka <email@hidden>)
 >Re: blocks and id (From: Andreas Grosam <email@hidden>)
 >Re: blocks and id (From: "email@hidden" <email@hidden>)

  • Prev by Date: Re: blocks and id
  • Next by Date: Re: blocks and id
  • Previous by thread: Re: blocks and id
  • Next by thread: Re: blocks and id
  • Index(es):
    • Date
    • Thread