• 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: Cancelable NSBlockOperations
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Cancelable NSBlockOperations


  • Subject: Re: Cancelable NSBlockOperations
  • From: Michael Ash <email@hidden>
  • Date: Thu, 14 Jan 2010 15:42:14 -0500

On Thu, Jan 14, 2010 at 3:15 PM, Jamie Hardt <email@hidden> wrote:
> On Jan 14, 2010, at 12:07 PM, Nick Zitzmann wrote:
>
>> Sorry, forgot that block operations, unlike invocation operations, don't take arguments. (Guess which one I use more often?) Yes, I'd try what you're proposing.
>
> It was a good though, but doing something like this...
>
> NSBlockOperation *b = [NSBlockOperation blockOperationWithBlock:^{
>
>      /* do stuff */
>
>      if ([b isCancelled]) {
>
>        /* clean up and rejoin */
>
>      }
> }];
>
> [queue addOperation:b];
>
> ...fails horribly.  The debugger looks strange, I can't make sense of it.

Despite how it may look, the order of operations screws you up.

The block gets created first, and only after that happens does the
assignment to b occur. But creating the block copies the value of b.
Because that copy happens before initialization, you get the old,
uninitialized, garbage value of b.

It's easy to fix, though. Just make it so that the block can follow
changes to the value of b that happen after the block is created, by
declaring b with the __block qualifier.

Mike
_______________________________________________

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: 
 >Cancelable NSBlockOperations (From: Jamie Hardt <email@hidden>)
 >Re: Cancelable NSBlockOperations (From: Nick Zitzmann <email@hidden>)
 >Re: Cancelable NSBlockOperations (From: Jamie Hardt <email@hidden>)
 >Re: Cancelable NSBlockOperations (From: Nick Zitzmann <email@hidden>)
 >Re: Cancelable NSBlockOperations (From: Jamie Hardt <email@hidden>)

  • Prev by Date: Re: NSArrayController Conceptual Problem
  • Next by Date: Re: Trying to create an alias file by using the new NSURL methods available with Mac OS X 10.6 !
  • Previous by thread: Re: Cancelable NSBlockOperations
  • Next by thread: Re: UITableView with cells of varying heights
  • Index(es):
    • Date
    • Thread