-(void)saveDictionary:(int)counter
{
NSString *path=[[NSBundle mainBundle] pathForResource:@"Data" ofType:@"plist"];
NSString *test = [NSString stringWithFormat:@"%d", counter];
[theDictionary setObject:test forKey:@"Counter"]; <---- Error
[theDictionary writeToFile:path atomically:YES];
}
- (void)applicationDidEnterBackground:(UIApplication *)application
{
[self saveDictionary:[_viewController counter]];
}
오류 "인식 할 수없는 선택기 인스턴스로 전송"NSMutableDictionary
-[NSCFString setObject:forKey:]: unrecognized selector sent to instance
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSCFString setObject:forKey:]: unrecognized selector sent to instance
내가 PLIST에서 키 "카운터"의 값을로드 할 수 있습니다. 동일한 "카운터"키의 새 값을 저장하려면 ... 오류. 도움, 시간을 보냈습니다. 그것을 발견
-(void)initDictionary {
if (theDictionary == nil) {
NSString *path=[[NSBundle mainBundle] pathForResource:@"Data" ofType:@"plist"];
theDictionary = [[NSMutableDictionary alloc] initWithContentsOfFile:path];
theString = [theDictionary objectForKey:@"Counter"];
}
}
:
여기
안녕
는theDictionary
를 초기화하는 코드입니다!
theString = [[NSString alloc] initWithFormat:[theDictionary objectForKey:@"Counter"]];
감사합니다!