开发者

Objective C read-only int? What?

开发者 https://www.devze.com 2023-03-20 18:33 出处:网络
I made an int to count how many suc开发者_开发问答cesses one of my processes has. Outside my code, I declare:

I made an int to count how many suc开发者_开发问答cesses one of my processes has. Outside my code, I declare:

int successes = 0.

Then within my loop, I have successes++;, at which point XCode complains that "variable is not assignable (missing _block type specifier)".

What is going on? Why can't I increment my int? I never declared it read-only...

Any help is much appreciated.

The code I used is:

_block int successes = 0;

for(CLLocation *location in locationOutputArray)
{
    CLGeocoder *geocoder = [[CLGeocoder alloc] init];
    [geocoder reverseGeocodeLocation:location completionHandler:^(NSArray *placemarks, NSError *error)
     {
         if(placemarks && placemarks.count > 0)
         {
             successes++;
             CLPlacemark *topResult = [placemarks objectAtIndex:0];

             NSString *address = [NSString stringWithFormat:@"%@ %@,%@ %@", [topResult subThoroughfare],[topResult thoroughfare],[topResult locality], [topResult administrativeArea]];

             [addressOutputArray addObject:address];
             NSLog(@"%@",address);
         }

     }];

    [geocoder release];
}


Your loop is inside a block (^{...} syntax). Blocks cannot alter variables outside of the block without that variable having a __block specifier.


You tried accessing this int inside a block. Mark it as __block so it can be updated from within the block.

Blocks Programming Topics

0

精彩评论

暂无评论...
验证码 换一张
取 消