objective-ccocoansarchiving

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


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?


Solution

  • Use NSFileManager:

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