使用以下代码获取文件路径:
NSString *executableName = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleExecutable"];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSUserDomainMask, YES);
NSString *path = [paths objectAtIndex:0];
path = [path stringByAppendingPathComponent:executableName];
然后我想将数据保存到文件(settings.bundle)
NSString *filePath = [path stringByAppendingPathComponent:@"settings.bundle"];
[someString writeToFile:settingsPath atomically:YES encoding:NSUTF8StringEncoding error:&error];
错误:
Error Domain=NSCocoaErrorDomain Code=4 "The folder “settings.bundle” doesn’t exist." UserInfo=0x7ff8894cecc0 {NSFilePath=/Users/xxxx/Library/Application Support/AppName/settings.bundle, NSUserStringVariant=Folder, NSUnderlyingError=0x7ff8894a1750 "The operation couldn’t be completed. No such file or directory"}
但如果我 mkdir AppName 手册没有错误:
mkdir /Users/xxxx/Library/Application Support/AppName
所以我的问题是:Cocoa 不能在 osx 中自动创建文件夹?