많은 질문/자습서를 읽으려고했지만 대답을 찾을 수 없습니다!.plist (특성 목록) 파일에 NSString 추가
배열이//Save Name to plist
if([name.text length] > 0){
NSString *string = name.text;
[array addObject:string];
//plist path
NSString *path = [[NSBundle mainBundle] pathForResource:@"datas" ofType:@"plist"];
//save object
[array writeToFile: path atomically:YES];
}
입니다 : 나는 텍스트 필드로부터 문자열을 얻고 (기본 키 루트에서) 내가 만든 datas.plist 파일에 저장하기 위해 노력하고있어 나는이 코드를 시도했습니다 내가 WR 코드를 생각
* Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Cannot create an NSPersistentStoreCoordinator with a nil model'
:
@interface DetailViewController(){
NSMutableArray* array;
}
는 그러나 응용 프로그램 충돌이 오류를 제공 (내가 버튼에 연결하기 전에 쓴 작업)을 저장하려고하면 내가 키를 입력하지 않기 때문에 ites가 올바르지 않습니다 (예 : @ "Root") 또는 이와 비슷한. 사전에 감사
편집 :
나는이 코드를 시도했지만 아무것도 기록하지 않습니다
- (void)addToMyPlist {
NSString *destPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];
destPath = [destPath stringByAppendingPathComponent:@"dati"];
// If the file doesn't exist in the Documents Folder, copy it.
NSFileManager *fileManager = [NSFileManager defaultManager];
if (![fileManager fileExistsAtPath:destPath]) {
NSString *sourcePath = [[NSBundle mainBundle] pathForResource:@"dati" ofType:@"plist"];
[fileManager copyItemAtPath:sourcePath toPath:destPath error:nil];
}
// Load the Property List.
array = [[NSMutableArray alloc] initWithContentsOfFile:destPath];
//NSString *path = [[NSBundle mainBundle] pathForResource:@"dati" ofType:@"plist"];
NSString *string = self.name.text;
NSArray *values = [[NSArray alloc] initWithObjects:string, nil];
NSArray *keys = [[NSArray alloc] initWithObjects:@"Root", nil];
NSDictionary *dict = [[NSDictionary alloc] initWithObjects:values forKeys:keys];
[array addObject:dict];
[array writeToFile:destPath atomically:YES];
}
잘못 무엇을?
내가 원만이이 스택 오버플로 ... –
귀하의 PLIST 문제와 예외 (코어 데이터)에 요청 때마다 가지고있는 경우 것 같다 관련이없는 것 ... – Wain
@Bigood 그래, 내가 감사 했어 – r4id4