self.toDoItems = [[NSMutableArray alloc] init]; //initialize array
self.dataFileName = @"PropertyList";
self.filePath = [self.dataFileName stringByAppendingString:@".plist"];
self.rootPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,
NSUserDomainMask, YES) objectAtIndex:0];
self.filePath = [self.rootPath stringByAppendingPathComponent:self.filePath];
self.NSSRootNodeName = @"ToDoList"; //name of the root node in the property list
// if (![[NSFileManager defaultManager] fileExistsAtPath: self.filePath]) {
// self.filePath = [[NSBundle mainBundle] pathForResource:self.dataFileName ofType:@"plist"];
// }
NSLog(@"File path: %@", self.filePath);
// Uncomment the following line to preserve selection between presentations.
self.clearsSelectionOnViewWillAppear = NO;
// Uncomment the following line to display an Edit button in the navigation bar for this view controller.
self.navigationItem.rightBarButtonItem = self.editButtonItem;
//read xml file and load to array
NSString *errorDesc = nil;
NSPropertyListFormat format;
NSData *plistXML = [[NSFileManager defaultManager] contentsAtPath:self.filePath];
if (plistXML==nil) {
NSLog(@"Error reading plistXML");
}
NSDictionary *rootDictionary = (NSDictionary *)[NSPropertyListSerialization
propertyListFromData:plistXML
mutabilityOption:NSPropertyListMutableContainersAndLeaves
format:&format
errorDescription:&errorDesc];
if (!rootDictionary) {
NSLog(@"Error reading plist: %@, format: %d", errorDesc, format);
}
출력이 아래에 있습니다. 왜 이러한 오류가 아래에 표시되는지 잘 모르겠습니다. 내 PropertyList.plist가 내 애플리케이션의 내 문서 폴더에 있습니다. 누군가 내가 잘못하고있는 것을 지적 할 수 있습니다.objective-c가 속성 목록에서 읽을 수 없습니다.
File path: /Users/Computer/Library/Application Support/iPhone Simulator/7.1/Applications/78B5F9BA-8376-4001-ACA0-936D9B4D6342/Documents/PropertyList.plist
Error reading plistXML
Error reading plist: stream had too few bytes, format: 0
시도 확인 : 경우 ([[NSFileManager를 defaultManager] fileExistsAtPath : self.filePath]) contentsAtPath을 읽을 전에 : – stosha
을하면 I 않은 코멘트 애플리케이션 번들에 관한 내용. 읽기 부분에서 작동하지만 여전히 변경 사항을 특성 파일에 다시 써서 문제가 있습니다. ~/documents 폴더에서 파일을 찾을 수 없다면 Apple에 따르면 내 이해는 응용 프로그램 번들에서 시도 할 것이므로 감각을 만듭니다. 하지만 내 변경 사항을 다시 작성하려면 어떻게해야합니까? – HaiNguyen
@HaiNguyen : 응용 프로그램 번들에 * 쓸 수 없습니다. 읽기 전용입니다. 따라서 응용 프로그램 번들에서 plist를 읽은 경우에도 Documents 디렉토리 (또는 다른 쓰기 가능한 디렉토리)에 써야합니다. –