我有个问题。我想更改块中的局部变量。我什么都试过了。我把变量 __block 的开始,但没有什么可以改变。我不能改变块中的 myString 值。你可以帮帮我吗 ?这是我的代码:
- (IBAction)setButtonPressed:(id)sender {
placeName = [[[NSMutableString alloc] init] retain];
__block NSMutableString *myString = [[NSMutableString alloc] init];
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSDate *today = [NSDate date];
NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setDateFormat:@"dd.MM.yyyy hh:mm:ss"];
NSString *dateString = [dateFormat stringFromDate:today];
[previousParkingLon addObject:[NSNumber numberWithFloat:self.longitude]];
[previousParkingLat addObject:[NSNumber numberWithFloat:self.latitude]];
[previousParkingsDate addObject:dateString];
if((self.latitude != 0) && (self.longitude != 0))
{
self.geocoder = [[CLGeocoder alloc] init ];
[self.geocoder reverseGeocodeLocation:locationManager.location completionHandler:^(NSArray *placemarks, NSError *error) {
CLPlacemark *myplacemark = [placemarks objectAtIndex:0];
NSString *locatedAt = [[[myplacemark addressDictionary] objectForKey:@"FormattedAddressLines"] componentsJoinedByString:@", "];
[myString setString:locatedAt];
}];
}
[previousParkingsPlaceName addObject:placeName];
NSLog(@"Test %@",myString);
[defaults setObject:previousParkingLat forKey:@"historyLat"];
[defaults setObject:previousParkingLon forKey:@"historyLon"];
[defaults setObject:previousParkingsDate forKey:@"historyDate"];
[defaults setObject:previousParkingsPlaceName forKey:@"historyName"];
[defaults synchronize];
}