0
을 ArchiveRootObject
NSMutableArray *esami = [[NSMutableArray alloc] init];
NSArray *paths = NSSearchPathForDirectoriesInDomains
(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
//make a file name to write the data to using the
//documents directory:
NSString *fullFileName = [NSString stringWithFormat:@"%@/new", documentsDirectory];
esami = [NSKeyedUnarchiver unarchiveObjectWithFile:fullFileName];
Esame *add=[[Esame alloc]initWithNome:materia voto:voto crediti:crediti anno:anno];
[esami addObject:add];
[NSKeyedArchiver archiveRootObject:esami toFile:fullFileName];
이미 내 루트 디렉토리로 작성된 파일을 사용하는 경우이 코드는 .. 작동하지 않습니다 내 배열에 새 요소를 추가하고 쓸 수 있습니다 내가 왜 understad 수 없습니다 하지만 다른 파일 (이 경우 새로운 파일)을 사용하면 작동하지 않습니다.쓰기 배열
바퀴를 재발 명하지 마십시오. NSString * fullFileName = [documentsDirectory stringByAppendingPathComponent : @ "new"]; ' –
괜찮습니다.하지만 아무 것도 바뀌지 않습니다! –
그게 내가 이것을 asnwer라고 덧붙여 말하지 않은 이유입니다. –