我正在尝试在后台添加标记,以防止地图在添加时变得无响应,但我看到了一个我以前从未遇到过的错误。
这是我在后台加载标记的尝试,并且在尝试发送 addMarkerWithOptions 时发生错误。
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
NSLog(@"yeap im in the background %i, markers=%i", [[self visibleLocations] count], [[[self googleMap] markers] count]);
for (int i = 0; i < self.visibleLocations.count; i++) {
Location *location = [self.visibleLocations objectAtIndex:i];
GMSMarkerOptions *options = [[GMSMarkerOptions alloc] init];
options.position = CLLocationCoordinate2DMake([location.lat floatValue], [location.lng floatValue]);
options.title = [NSString stringWithFormat:@"(%i) %@", location.mapNeighbors.count, location.title];
options.icon = [UIImage imageNamed:@"search_measle_small.png"];
[self.googleMap addMarkerWithOptions:option];
}
});
错误
yeap im in the background 860, markers=0
2013-04-20 14:02:11.561 Skate-Spots[7796:907] *** Terminating app due to uncaught exception 'NSGenericException', reason: '*** Collection <__NSSetM: 0x1d6e7880> was mutated while being enumerated.'
*** First throw call stack:
(0x336a23e7 0x3b39d963 0x336a1ec1 0x16ea0d 0x3b7b7793 0x3b7b75db 0x3b7bae45 0x336761b1 0x335e923d 0x335e90c9 0x371c833b 0x355052b9 0x112e5 0x3b7cab20)
libc++abi.dylib: terminate called throwing an exception