Re: NSOperationQueue and for-loop
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