가 어떻게이 PLIST에서 NSDictionary와의 기존 키에 값을 추가 할 수있는 PLIST에 저장? 내가 가진 무엇추가] 항목
는 기본적으로 몇 개의 키와 값을 사용하여 디스크에 저장된 PLIST이며, 키는 하나 개의 초기 값 일부 학생의 이름입니다. 내가 그 일을하려고 노력하고있어 기존의 키/학생에게 plist를 읽고, 임시 NSDictionary에 추가하여, plist의 기존 키에 임시 배열을 추가하지만 더 많은 항목을 추가하는 것입니다. plist가 작동하지 않으면 마지막 두 항목 만 저장하고 기본적으로 해당 키의 초기 값을 삭제합니다. 여기
내가 여기 실종 내가 사용하고 코드 ...- (IBAction)testing:(id)sender
{
NSArray *dirPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsPath = [dirPaths objectAtIndex:0];
NSString *fullPath = [documentsPath stringByAppendingPathComponent:@"studentsRecords.plist"];
BOOL fileExists = [[NSFileManager defaultManager] fileExistsAtPath:fullPath];
if(fileExists)
{
NSMutableDictionary *dictionaryRecords = [[NSMutableDictionary alloc]initWithContentsOfFile:fullPath];
NSLog(@"Items for Nathan: %@",[dictionaryRecords objectForKey:@"Nathan"]);// here the output is, Items for Nathan: Ruler
// which make sense since I only had one initial record for Nathan in my plist,
// Here, I want to add two more items to the key Nathan by appending an arry to
// NSMutableDictionary (dictionaryRecords) but it doesnt work
NSArray *tempArray = @[@"NoteBook", @"Pencil"];
[dictionaryRecords setObject:tempArray forKey:@"Nathan"];
[dictionaryRecords writeToFile:fullPath atomically:YES];
// when I check the plist after saving this, I only see the last two values, NoteBook and Pencil
// instead of the three that I'm expecting, Ruler, NoteBook and Pencil
}
}
입니까?
미리 감사드립니다. 이전 값이 tempArray
로했다 어떤
는 PLIST에서 검색? 실례지만 어떻게 할 수 있습니까? 죄송 합니다만, 이미 알고 계시 겠지만 plists와 NSDictionaries에 대한 많은 경험이 없습니다. –
질문에 이미있는 코드가 있습니다. 'dictionaryRecords'는 plist의 내용입니다. –
알아요.하지만 변경할 수있는 사본을 만들려면 어떻게해야합니까? 감사합니다 –