How can you determine if a file exists within the app bundle?

后端 未结 5 689
星月不相逢
星月不相逢 2021-02-01 12:55

Sorry, dumb question number 2 today. Is it possible to determine if a file is contained within the App Bundle? I can access files no problem, i.e.,

NSString *p         


        
5条回答
  •  -上瘾入骨i
    2021-02-01 13:19

    This code worked for me...

    NSString *pathAndFileName = [[NSBundle mainBundle] pathForResource:fileName ofType:nil];
    if ([[NSFileManager defaultManager] fileExistsAtPath:pathAndFileName])
    {
        NSLog(@"File exists in BUNDLE");
    }
    else
    {
        NSLog(@"File not found");
    }
    

    Hopefully, it will help somebody...

提交回复
热议问题