2012-10-05 3 views
0

속성 목록 파일에 저장하려고 시도했지만 실제 파일 자체가 아니라 배열에 개체를 저장하는 것으로 작동하지 않습니다. 즉, 저장되는 내용이 분명히 유지되지 않습니다. ,속성 목록 (plist) 파일에 문자열을 저장 하시겠습니까?

NSArray *paths=NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES); 
NSString *documentsDirectory = [paths objectAtIndex:0]; 
NSString *plistFilePath = [documentsDirectory stringByAppendingPathComponent:fileNameFull]; 

if([[NSFileManager defaultManager] fileExistsAtPath:plistFilePath]) { 

    category = [NSMutableArray arrayWithContentsOfFile:plistFilePath]; 

    NSLog(@"Files exist."); 

} 
else { 

    filePath = [[NSBundle mainBundle] pathForResource:fileNamer ofType:@"plist"]; 
    category = [NSMutableArray arrayWithContentsOfFile:filePath]; 

    NSLog(@"Files have been created."); 

} 

내 재산 목록을 배열로 구성되어 있습니다 :

[[category objectAtIndex:questionCounter] replaceObjectAtIndex:5 withObject:myString]; 
[category writeToFile:filePath atomically:YES]; 

은 내가 편집하고 저장할 수 있도록 문서 디렉토리에 재산 목록 파일을 저장하려면이 이전을에 사용하고 있습니다 이러한 배열 내 개체 (문자열) 저장하려고 해요. 나는 그것이 사소한 것이라고 느끼지만 그것을 발견 할 수 없다.

답변

2

배열을 저장하려고 할 때 쓸 수없는 기본 번들 디렉토리를 가리키는 filePath을 전달합니다. 대신 다음과 같이 을 사용하고 싶습니다.

[category writeToFile:plistFilePath atomically:YES]; 
관련 문제