• 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: NSOperationQueue and for-loop
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSOperationQueue and for-loop


  • Subject: Re: NSOperationQueue and for-loop
  • From: email@hidden
  • Date: Tue, 02 Oct 2012 18:07:58 -0400

On Oct 2, 2012, at 5:49 PM, Koen van der Drift <email@hidden> wrote:

> Hi,
>
> When looking how to implement an NSOperationQueue with a loop, I found several examples that have the following structure:
>
> 	NSInteger  i;
>
>            for ( i = 0; i < 1000; i++ ) {
>                [queue addOperationWithBlock:^{
>                    i += 1;
>                }];
>            }
>
> But I get a compiler error:  Variable is not assignable (missing __block type specifier)
>
> I solved by declaring the declaration for i:
>
> 	NSInteger __block i;
>
> But why does it work in the examples I found?
>
> Thanks,
>
> - Koen.

I can't speak to the other examples since I haven't seen them, but the __block specifier is necessary if your block modifies the variable (your block does modify i). Your example also seems a bit strange since your for loop modifies i itself.

Dave

_______________________________________________

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

  • Follow-Ups:
    • Re: NSOperationQueue and for-loop
      • From: Koen van der Drift <email@hidden>
References: 
 >NSOperationQueue and for-loop (From: Koen van der Drift <email@hidden>)

  • Prev by Date: NSOperationQueue and for-loop
  • Next by Date: Re: NSOperationQueue and for-loop
  • Previous by thread: NSOperationQueue and for-loop
  • Next by thread: Re: NSOperationQueue and for-loop
  • Index(es):
    • Date
    • Thread