GaleDragon
GaleDragon

Reputation: 138

Finding a Resource Text File

Just to begin, I've read Read text file in a folder and other troubleshooting things on here, and I've followed the advice previously given.

However, my program still can't find my .txt file.

I've checked the name, the bundle resources, and the file itself, and everything seems to be in order. My code runs fine, and I get my own error message when it can't find the file. No crashes or anything out of the ordinary.

I've also changed the Preferences/Locations/Build Location to "Place Build Products in locations specified by targets." which was an issue before.

Any additional help?

Thanks in advance!

    #import "FileArrayControl.h"


@implementation FileArrayControl

@synthesize partArray, arrayContent;

- (NSArray *) setFileToArray {

    NSString *stemFile = [[NSBundle mainBundle] pathForResource:@"stemList.txt" ofType:@"txt" inDirectory:@"stemIDv0"];

    if (stemFile != nil) {

        // ...stuff...


    } else {
        NSLog(@"Error, file not found!");
    }
    NSLog(@"%@",partArray);
    return partArray;
}


@end

enter image description here

Upvotes: 2

Views: 749

Answers (1)

Rob Napier
Rob Napier

Reputation: 299275

You're incorrectly using pathForResource:ofType:inDirectory:. This method should not include the extension in the first parameter. So it would be:

NSString *stemFile = [[NSBundle mainBundle] pathForResource:@"stemList" ofType:@"txt" inDirectory:@"stemIDv0"];

Upvotes: 2

Related Questions