How to create a private directory in the library directory and give it the name of the application package identifier?

Apple talks about this in this document here and here .

I would not want to reinvent the wheel, and I'm sure someone did it, but I was not lucky with Google. Does anyone know a blog that points out how to do this?

The problem is that I have to create this directory with the application package identifier identifier inside the library, but only if it does not exist.

+3
source share
1 answer

I think this is what you are looking for:

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES);
NSString *libraryPath = [paths objectAtIndex:0];
NSString *bundlePath = [libraryPath stringByAppendingPathComponent:[[NSBundle mainBundle] bundleIdentifier]];
if(![[NSFileManager defaultManager] fileExistsAtPath:bundlePath]) {
    [[NSFileManager defaultManager] createDirectoryAtPath:bundlePath withIntermediateDirectories:YES attributes:nil error:NULL];
}
+5
source

All Articles