我是一个Objective C菜鸟,我不太了解以下问题.
此代码有效:
NSString *plistPath = @"/Users/andrewf/MyApp/Resources/Plates.plist";
dicPlates = [[NSDictionary alloc] initWithContentsOfFile:plistPath];
Run Code Online (Sandbox Code Playgroud)
我的字典对象按预期加载了值.
此代码不起作用:
NSString *plistPath = [[NSBundle mainBundle] pathForResource:@"Plates" ofType:@"plist"];
dicPlates = [[NSDictionary alloc] initWithContentsOfFile:plistPath];
Run Code Online (Sandbox Code Playgroud)
plistPath返回值为nil.无论我是否在调用中包含inDirectory:@"Resources",情况都是如此.尝试在Resources目录中打开.plist文件时,我发现的所有示例都不包含inDirectory.
我已经确认该文件存在于正确的位置,甚至可以重新创建它.
这似乎是一个简单的问题,但我很神秘.请协助.