我做了一個int來計算我的一個進程有多少成功。在我的代碼之外,我聲明:Objective C只讀int?什麼?
int successes = 0
。
然後在我的循環中,我有successes++;
,此時XCode抱怨「變量不可分配(缺少_block類型說明符)」。
這是怎麼回事?爲什麼我不能增加我的int值?我從來沒有宣佈它只讀...
任何幫助,非常感謝。
我使用的代碼是:
_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];
}
你試過'__block int successes = 0;'?你最好展示你的代碼,因爲很明顯你使用的是塊或者其他你沒有告訴我們的東西。 – jtbandes
只是爲了確認,這是一個多線程應用程序? –