plist에서 데이터를 먼저 검색하고, 데이터를 추가하고, plist 파일에 전체 내용을 다시 써야한다는 것을 알고 있습니다.xcode로 plist 할 데이터 저장
내 코드는 여기에 추가되지 않지만이 메소드를 호출 할 때마다 새로 고침됩니다.
- (void) saveDataToPlist {
// Retrieve path and filename of the plist file
NSString *myColorsListFile = [self dataFilePath];
NSMutableArray *innerArray1;
NSString *error;
UserGivenColorHexString = HexTextField.text;
NSMutableDictionary *rootObj = [NSMutableDictionary dictionaryWithCapacity:100];
if ([[NSFileManager defaultManager] fileExistsAtPath:myColorsListFile]) {
// File exists
rootObj = [[NSMutableDictionary alloc] initWithContentsOfFile:myColorsListFile];
[innerArray1 addObjectsFromArray:[NSMutableArray arrayWithContentsOfFile:myColorsListFile]];
[innerArray1 addObject:UserGivenColorName];
} else {
// Create file
rootObj = [[NSMutableDictionary alloc] init];
innerArray1 = [NSMutableArray arrayWithObjects: UserGivenColorName, nil];
[rootObj setObject:innerArray1 forKey:@"ColorName"];
}
id plist = [NSPropertyListSerialization dataFromPropertyList:(id)rootObj format:NSPropertyListXMLFormat_v1_0 errorDescription:&error];
[plist writeToFile:myColorsListFile atomically:YES];
}
롭, 나는 귀하의 게시물/솔루션 UP 투표를 할 수있는 충분한 명성을 필요가 없습니다. 그러나 만약 내가 할 수 있다면 100 배나 더 많이했을 것입니다. 귀하의 솔루션은 완벽하게 작동하며 모든 의견은 높이 평가됩니다. 감사! – user3477156