당신이 정말로 상자에서 개체를 저장해야하는 경우, 나는있는 NSDictionary에로드 것입니다 그리고 그것을 쓰는 :
참고 : 이것은 단지 시작 지점 의도 안된/비 생산 코드입니다.
- (BOOL)saveBox:(Box*)aBox;
{
NSMutableDictionary *boxDict = [NSMutableDictionary dictionaryWithCapacity:10];
// Add contents of box to dictionary (exercise left up to original poster)
// boxDict is now populated
// write dictionary to apps document directory.
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
if (!documentsDirectory) {
NSLog(@"Documents directory not found!");
return NO;
}
// Assumes Box class has name property
NSString *outputFile = [documentsDirectory stringByAppendingPathComponent:[aBox name]];
return [boxDict writeToFile:outputFile atomically:YES];
}
사용자의 필요에 따라 파일 이름 등을 반환하도록 쉽게 수정할 수 있습니다.
왜 파일을 번들로 저장 하시겠습니까? 사용자는 이러한 파일/폴더를 절대로 볼 수 없습니다. – kubi
죄송합니다. CoreData를 사용하고 있습니다. 그래서 저는이 모든 참조를 String으로 저장하는 것을 선호합니다. 어쨌든 사용자는 이러한 파일을 보지 못하지만 다운로드되어 클라이언트 응용 프로그램으로 가져옵니다. 그래서 압축 할 수 있고 돌아 다니는 멋진 패키지를 만드는 것이 나의 목표 중 하나입니다. – sysco