objective-c - 为什么带有属性的 createDirectory AtPath 不起作用

标签 objective-c macos cocoa

在 OS X 桌面应用程序中

NSFileManager *manager = [NSFileManager defaultManager];

NSDictionary *dirMeta = [NSDictionary dictionaryWithObjectsAndKeys:@"jack", @"creator", nil];
NSLog(@"%@", [dirMeta objectForKey:@"creator"]);//output jack

[manager createDirectoryAtPath:@"/Users/loki/Desktop/fromCap" withIntermediateDirectories:YES attributes:dirMeta error:NULL];

NSDictionary *attri2 = [manager attributesOfItemAtPath:@"/User/loki/Desktop/fromCap" error:nil];
NSLog(@"value is %@", [attri2 objectForKey:@"creator"]);//output null

我是否错误地使用了createDirectoryAtPath? 为什么 attri2 从目录中得不到任何数据?

最佳答案

attributes字典用于指定新目录/文件的文件系统属性:

attributes The file attributes for the new directory and any newly created intermediate directories. You can set the owner and group numbers, file permissions, and modification date. If you specify nil for this parameter or omit a particular value, one or more default values are used as described in the discussion. For a list of keys you can include in this dictionary, see “Constants” section lists the global constants used as keys in the attributes dictionary. Some of the keys, such as NSFileHFSCreatorCode and NSFileHFSTypeCode, do not apply to directories.

它们不用于附加任意元数据。您认为这些元数据将存储在哪里?

关于objective-c - 为什么带有属性的 createDirectory AtPath 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12857065/

相关文章:

iphone - Objective-C - NSNotificationCenter 放在哪里?

excel - 在 Excel 公式中插入换行符 (MacOS)

objective-c - 将自身属性传递给 block 时的 ARC 实现

objective-c - NSView - 如何在不重绘父 View 的情况下重绘 subview

iOS - 应用程序运行时不显示推送通知警报

iphone - 我可以为 Cocoa Touch 应用程序开发自己的 objective-C 框架吗?

ios - 将链接放在 UIWebView 中并显示在不同的 View Controller 上

macos - 启动使用 Clang 构建的 MacOS 应用程序时出错

cocoa - 更改 CALayer 属性的动画时间

objective-c - NSColor colorwithpatternimage 将 NSView 绘制为黑色