开发者

Unable to load file in iOS app; Cocoa error 260

I'm pulling my hair out right now because the app I'm trying to test can't locate a config file.

The following code fails to load my file and returns the error string: "The operation couldn’t be completed. (Cocoa error 260.)", which Google translated as "Read error (no such file)".

-(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"];

I'm an XCode newbie, so maybe I'm missing some step in setting up the project. All I've done so far is add "config.txt" to the Res开发者_高级运维ources folder the project template set up for me.

As always, any help would be greatly appreciated. Thanks!


Are you getting the path from your NSBundle? You should have the output of something like [[NSBundle mainBundle] pathForResource:@"config" ofType:@"txt"] getting passed into your initFromPath: method.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜