简体   繁体   中英

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 Resources 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM