问题
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