How to get file path? Loading documents in Document based app

爷,独闯天下 提交于 2019-12-14 03:09:19

问题


I want to be able to save and load documents, so I'm trying to use these methods:

[NSKeyedArchiver archiveRootObject: rootObject toFile: @"myMap.map"];

rootObject = [NSKeyedUnarchiver unarchiveObjectWithFile:@"myMap.map"];

What am I meant to put as the file argument? I just have a constant string for now, but that means I can only load one file, I assume there's a way to get the user's selection from the open panel to be the argument, but how?


回答1:


Use NSFileManager:

NSArray *allFileNames = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:@"SomeDirectory"];



回答2:


I found the solution, I now use this method:

[NSKeyedArchiver archivedDataWithRootObject:rootObject];

Which saves data to the file the user choses in the save/load panel. I still don't know how to access the document's path, but this works good enough.



来源:https://stackoverflow.com/questions/12723032/how-to-get-file-path-loading-documents-in-document-based-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!