You are writing a Mac Cocoa application, and you know you want to store your user specific application support files in a predictable location, like ~/Library/Application Support/<Application>/. So... how exactly do we do that?
Once again, Google to the rescue, and we find the answer at Cocoa Dev Central. This will not only construct the file name for you, but it will create the directory if it doesn't exist, too.
- (NSString *) pathForDataFile {
NSFileManager *fileManager = [NSFileManager defaultManager];
NSString *folder = @"~/Library/Application Support/MyApplication/";
folder = [folder stringByExpandingTildeInPath];
if ([fileManager fileExistsAtPath: folder] == NO) {
[fileManager createDirectoryAtPath:folder attributes: nil];
}
NSString *fileName = @"MyApplication.mysettings";
return [folder stringByAppendingPathComponent: fileName];
}
Again, an example that just works. I'm on a roll today.



