无法在iOS应用中加载文件; 可可错误260

use*_*133 4 cocoa-touch ios

我正在把头发拉出来,因为我正在尝试测试的应用程序找不到配置文件.

以下代码无法加载我的文件并返回错误字符串:"操作无法完成.(Cocoa错误260.)",谷歌翻译为"读取错误(没有这样的文件)".

-(id) initFromPath:(NSString *)path
{
    NSError **e;
    NSData *d = [NSData dataWithContentsOfFile:path options:NSDataReadingMapped error:e];

    if(e != nil)
    {
        NSLog(@"%@", [*e localizedDescription]);
    }
    [self initFromData:d];
    return self;
}

... //snip

[MyClass initFromPath:@"config.txt"];
Run Code Online (Sandbox Code Playgroud)

我是一个XCode新手,所以也许我错过了设置项目的一些步骤.到目前为止我所做的就是将"config.txt"添加到项目模板为我设置的Resources文件夹中.

一如既往,任何帮助将不胜感激.谢谢!

Arc*_*gon 5

你是从NSBundle那里得到的吗?您应该输出类似于[[NSBundle mainBundle] pathForResource:@"config" ofType:@"txt"]传递到您的initFromPath:方法的输出.