2 개의 NSMutableDictionary를 가진 클래스가 있다고 해봅시다.NSMutableDictionary 이상한 문제
@interface GameDataManager : CCNode {
NSMutableDictionary *worldInfoDictionary;
NSMutableDictionary *levelInfoDictionary;
}
@property (nonatomic, retain) NSMutableDictionary *worldInfoDictionary;
@property (nonatomic, retain) NSMutableDictionary *levelInfoDictionary;
앱은 다음과 같이 시작하는 동안이 PLIST에서 데이터를로드 :
-(BOOL) readApplicationData:(NSString *)fileName
{
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *appFile = [documentsDirectory stringByAppendingPathComponent:fileName];
NSData *myData = [[[NSData alloc] initWithContentsOfFile:appFile] autorelease];
if (myData == nil) {
return NO;
}
NSKeyedUnarchiver *un = [[NSKeyedUnarchiver alloc] initForReadingWithData:myData];
NSMutableDictionary *dic = [un decodeObjectForKey:@"GameData"];
self.worldInfoDictionary = [dic objectForKey:@"WorldInfoDictionary"];
self.levelInfoDictionary = [dic objectForKey:@"LevelInfoDictionary"];
for (int i = 1; i <= 10; i++) {
WorldInfoData * w = [worldInfoDictionary objectForKey:
[[[NSString alloc] initWithFormat:@"World%d", i] autorelease]];
NSLog(@"%d", w.worldNum);
[w release];
}
[un finishDecoding];
[un release];
return YES;
}
을 다음 두 줄 후 :
self.worldInfoDictionary = [dic objectForKey:@"WorldInfoDictionary"];
self.levelInfoDictionary = [dic objectForKey:@"LevelInfoDictionary"];
내가 볼 수있는 값의 수를/두 개의 사전에있는 키가 맞습니다.
은 그럼 각 개체하지만 응용 프로그램 crahed에 대한 모든 "worldNum"값을 출력하려고 :
2011-03-07 15:18:21.819 [1267:207] 1
2011-03-07 15:18:21.820 [1267:207] 2
2011-03-07 15:18:21.821 [1267:207] 3
2011-03-07 15:18:21.823 [1267:207] 4
2011-03-07 15:18:21.831 [1267:207] 5
2011-03-07 15:18:21.832 [1267:207] 6
2011-03-07 15:18:21.832 [1267:207] 7
2011-03-07 15:18:21.833 [1267:207] 8
2011-03-07 15:18:21.834 [1267:207] 9
2011-03-07 15:18:21.834 [1267:207] 10
Stack dump:
0. Running pass 'Sparse Conditional Constant Propagation' on function '@gleLLVMVecProjectionTransform2'
나는이 라인의 주석을 해제하는 경우 :
[un release];
응용이 잘 작동을, 부수 지 마시오.
은 누구 덕분에 많은^_^모든 답변을
감사합니다, 나에게 이것을 설명 할 수 있습니다. 내가 코드 라인을 삭제하면
는하지만 출력에 약간의 정보 사용 :
for (int i = 1; i <= 10; i++) {
WorldInfoData * w = [worldInfoDictionary objectForKey:
[[[NSString alloc] initWithFormat:@"World%d", i] autorelease]];
NSLog(@"%d", w.worldNum);
[w release];
}
을 그리고 라인의 주석 "[유엔 릴리스]"는 readApplicationData이 , 잘 작동하지만 난을 읽으려고 할 때 이후 이와 같은 데이터 :이 광고 후
NSMutableDictionary *dic = [GameDataManager sharedGameDataManager].worldInfoDictionary;
for (int i = 1; i <= 10; i++) {
NSString *key = [[NSString alloc] initWithFormat:@"World%d", i];
WorldInfoData *worldInfoData = [dic objectForKey:key];
if (worldInfoData.worldNum == 1) {
//......
}
[key release];
}
"worldInfoData * worldInfoData = DIC objectForKey : 키]"worldInfoData 유형하지 worldInfoData *이지만 CCArray 및 CCArray 때문에 속성이없는 worldNum, 추락했습니다. ......
finishDecoding 기능에는 어떤 것이 있습니까? –
그것은 NSKeyedUnarchiver의 기능입니다 ... – supersurabbit