【发布时间】:2011-12-27 02:05:43
【问题描述】:
此代码导致错误,可能是什么问题? 我读过一些关于锁的东西,不可变对象在多个线程上使用时很容易崩溃。但我真的不知道那是怎么回事......
-(void)cleanUpAllHexagons{
//Cleaning up all hexagons from previous level
NSLog(@"cleaning hexagons");
NSString *spriteKey;
NSString *touchAreaKey;
NSMutableDictionary *existingHexagons = [[GameStateSingleton sharedMySingleton]getExistingHexagons];
for (int i= 0; i < [existingHexagons count]; i++){
spriteKey = [NSString stringWithFormat:@"hexagon%d",i];
for (spriteKey in existingHexagons) {
NSLog(@"the spritekey = %@",spriteKey);
NSLog(@"%@", existingHexagons);
NSLog(@"%@", [[existingHexagons valueForKey:spriteKey]objectForKey:@"realSprite"]);
[self removeChild:[[existingHexagons valueForKey:spriteKey]objectForKey:@"realSprite"] cleanup:YES];
[existingHexagons removeObjectForKey:spriteKey];
}
hexTouchAreas = [[GameStateSingleton sharedMySingleton]getSharedHexTouchAreas];
touchAreaKey = [NSString stringWithFormat:@"hexTouchArea%d",i];
for (touchAreaKey in hexTouchAreas) {
NSLog(@"the touchAreakey = %@",touchAreaKey);
NSLog(@"%@", [hexTouchAreas valueForKey:touchAreaKey]);
[self removeChild: [hexTouchAreas valueForKey:touchAreaKey] cleanup:YES];
}
}
}
【问题讨论】:
-
我认为这是因为您在枚举字典时正在修改字典.... [existingHexagons removeObjectForKey:spriteKey];是导致错误的地方。
标签: iphone objective-c ios ipad cocos2d-iphone