Question

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?

Was it helpful?

Solution

Use NSFileManager:

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

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top