我正在尝试通过实现(在 blablabla.m 中)创建一个“saveState”方法:
-(void)saveState {
NSString *masterCode = [[NSString alloc] initWithString:first];
masterCode = [masterCode stringByAppendingString:second];
masterCode = [masterCode stringByAppendingString:third];
masterCode = [masterCode stringByAppendingString:fourth];
NSLog(@"master passcode - %@", masterCode);
NSString *plistPath = [NSTemporaryDirectory() stringByAppendingPathComponent:@"timeLimiterMasterCode.plist"];
if (![[NSFileManager defaultManager] fileExistsAtPath:plistPath]) {
[[NSFileManager defaultManager] createFileAtPath:plistPath contents:nil attributes:nil];
}
if ([[NSFileManager defaultManager] fileExistsAtPath:plistPath]) {
NSLog(@"file exists, %@", plistPath);
}
NSMutableDictionary *plistCode = [NSMutableDictionary dictionaryWithContentsOfFile:plistPath];
[plistCode setObject:masterCode forKey:@"MasterCode"];
NSLog(@"whole plist - %@", plistCode);
[plistCode writeToFile:plistPath atomically: YES];
NSLog(@"master passcode from file - %@", [plistCode objectForKey:@"MasterCode"]);
}
masterCode 不是空的,在 blablabla.h 文件中我使用协议 UIApplicationDelegate,“文件存在”但应用程序返回:2013-01-29 12:19:50.496 timeLimiter[916:907] 整个 plist - (null) 2013-01 -29 12:19:50.500 timeLimiter[916:907] 文件中的主密码 - (null)
除了在 viewController (.m, .h) 中,我使用另一个 plist 和 write 方法并且工作正常。
我发现 [plistCode setObject:masterCode forKey:@"MasterCode"] 是山。我试图用@“test”替换'masterCode',但没有任何意义。
你能解决我的问题吗?请?