Search code examples
iosobjective-cfoundationnsbundle

NSBundle files with the same name but different Upper / Lower case at first letter


I have been working on a project where I added a file into the app bundle. I didn't relise that the project already included the same name file but with a small difference. The difference is the first letter in name in upper/lower case. I wanted to know how the foundation framework classes load resources in such a case.


Solution

  • Here is a test:

    NSString *pathentities = [[NSBundle mainBundle] pathForResource:@"entities" ofType:@"json"];
    NSString *pathEntities = [[NSBundle mainBundle] pathForResource:@"Entities" ofType:@"json"];
    NSError *error = nil;
    NSString *entities = [NSString stringWithContentsOfFile:pathentities encoding:NSUTF8StringEncoding error:&error];
    NSString *Entities = [NSString stringWithContentsOfFile:pathEntities encoding:NSUTF8StringEncoding error:&error];
    
    NSLog(@"entities : %@ , Entities : %@", entities, Entities);
    

    Entities.json file content: "Entities" entities.json file content: "entities"

    NSLog output:

    entities : Entities, Entities : (null)