0

I have images "hit_circle_0.png" through "hit_circle_19.png" in my resources folder but for some reason this code never passes the test for "found" The annoying thing is that I have the exact same function working in another method just below it. And the files are there in "Copy Bundle Resources"

NSMutableArray *hitCircle = [[NSMutableArray alloc]init];
for (int i = 0; i < 20; i++) {

    NSString *name = [NSString stringWithFormat:@"hit_circle_%i", i];
    NSString *filePath= [[NSBundle mainBundle] pathForResource:name ofType:@"png"];

    if ([[NSFileManager defaultManager] fileExistsAtPath:filePath]){
        NSLog(@"file %@ was found", filePath);
    } else{
        NSLog(@"%@ not found", filePath);
    } 
}
frankie
  • 661
  • 2
  • 10
  • 25

2 Answers2

0

I'm almost certain you're looking in the wrong subdirectory, and you need to use something like:

NSString *filePath= [[NSBundle mainBundle] pathForResource:name ofType:@"png" inDirectory:@"Hit_Circles"];

Or, if it's just in the Documents directory, you can get that using this, and then append your filename:

NSString* documentsPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
Aaron Brager
  • 65,323
  • 19
  • 161
  • 287
0

Just for kicks I went into the finder and renamed one of the files to exactly the same name and it loaded. Then I did the others - simply renaming them to the same name. I looked and there weren't any strange characters or whitespace before or after the file name. So now they all load fine into an array in the simulator. I still haven't figured out why.

frankie
  • 661
  • 2
  • 10
  • 25