我一直在尝试将字典复制到块中的NSMutableDictionary。
我试过了:
myMutableDictionary = [immutableDictionary copy]
" " = [immutableDictionary mutableCopy]
" " = [NSMutableDictionary alloc [initWithDictionary: immutableDictionary]
但是,每次尝试这个时,我都会得到EXC_BAD_ACCESS(代码= 2 ......)
我怀疑这与completionHandler中的迭代有关,但是无法想出另一种方法来构造它。
知道我做错了什么吗?
感谢您的帮助。
- (void) getCoordinatesForTheseLocations:(NSArray*) meetRecords
{
NSInteger countOfAnnotations = [meetRecords count];
if (debug==1) NSLog(@"countOfAnnotations equals %d", countOfAnnotations);
int __block iCount = 0;
for (__block NSDictionary* meet in meetRecords) {
if ([[meet objectForKey:MEET_STATE_ABBREV] isEqualToString:@"OR"] || [[meet objectForKey:MEET_STATE_ABBREV] isEqualToString:@"WA"]) {
NSString *location = [NSString stringWithFormat:@"%@, %@, %@",
[[meet objectForKey:MEET_VENUE] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]],
[[meet objectForKey:MEET_CITY] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]],
[[meet objectForKey:MEET_STATE_ABBREV] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]]];
CLGeocoder *geocoder = [[CLGeocoder alloc] init];
[geocoder geocodeAddressString:location completionHandler:^(NSArray *placemarks, NSError *error) {
CLLocationCoordinate2D coordinates;
CLPlacemark* bestGuess;
if (error)
{
NSString *message;
switch ([error code])
{
case kCLErrorGeocodeFoundNoResult:
message = @"kCLErrorGeocodeFoundNoResult";
break;
case kCLErrorGeocodeCanceled:
message = @"kCLErrorGeocodeCanceled";
break;
case kCLErrorGeocodeFoundPartialResult:
message = @"kCLErrorGeocodeFoundNoResult";
break;
default:
message = [error description];
break;
}
NSLog(@"Error of %@ for %@", message, location);
} else if(placemarks && placemarks.count > 0) {
NSMutableDictionary* meetInfoForAnnotation = [[NSMutableDictionary alloc] init];
meetInfoForAnnotation = [meet copy];
if (debug==1) NSLog(@"Received placemarks: %@", placemarks);
bestGuess = [placemarks objectAtIndex:0];
coordinates.latitude = bestGuess.location.coordinate.latitude;
coordinates.longitude = bestGuess.location.coordinate.longitude;
[meetInfoForAnnotation setObject:[NSNumber numberWithDouble:coordinates.longitude] forKey:MEET_LONGITUDE];
[meetInfoForAnnotation setObject:[NSNumber numberWithDouble:coordinates.latitude] forKey:MEET_LATITUDE];
[self mapAnnotations:meet];
}
if (debug==1) NSLog(@"iCount equals %d", iCount);
if (iCount == countOfAnnotations) {
dispatch_async(dispatch_get_main_queue(), ^{
// NSLog(@"%@",meetsWithCoordinates);
myPinColor = MKPinAnnotationColorPurple;
[self setAnnotations:self.meetAnnotations];
});
}
}];
iCount ++;
}
}
}
以下是错误日志的一部分。
libsystem_platform.dylib`OSAtomicCompareAndSwap32Barrier:
0x38973a28: ldrex r9, [r2]
libsystem_platform.dylib`OSAtomicCompareAndSwapPtrBarrier + 4:
0x38973a2c: movs r3, #0
0x38973a2e: cmp r9, r0
0x38973a30: bne 0x38973a5 ; OSAtomicCompareAndSwapPtrBarrier + 40
0x38973a32: dmb ishst
0x38973a36: strex r3, r1, [r2] Thread 1: EXC_BAD_ACCESS (code = address=0x2dc078ac)
0x38973a3a: cmp r3, #0
0x38973a3c: beq 0x38973a4a ; OSAtomicCompareAndSwapPtrBarrier + 34
0x38973a3e: ldrex r9, [r2]
0x38973a42: movs r3, #0
0x38973a44: cmp r9, r0
0x38973a46: bne 0x38973a50 ; OSAtomicCompareAndSwapPtrBarrier + 40
0x38973a48: b 0x38973a36 ; OSAtomicCompareAndSwapPtrBarrier + 14
0x38973a4a: movs r3, #1
0x38973a4c: dmb ish
0x38973a50: mov r0, r3
0x38973a52: bx lr