Add any files in your iOS application bundle and use it in the app.

Outline

You can add any files in your iOS application at build phase and use it in the app.

Add files

Add any files to your Xcode project. The following example add text file sample.txt. f:id:shindo1687:20200422215525p:plain

When you add files to the Xcode project, Xcode add them to Copy Bundle Resources in the Build Phases of project setting automatically. f:id:shindo1687:20200422220045p:plain

Build project and open application bundle by Finder. You can see copied file in it. f:id:shindo1687:20200422220409p:plain

Use it in your app

- (void)test {
    NSString* filePath = [[NSBundle mainBundle] pathForResource:@"sample" ofType:@"txt"];
    NSLog(@"filePath=%@", filePath);
    
    NSString* fileText = [NSString stringWithContentsOfFile:filePath encoding:NSUTF8StringEncoding error:nil];
    NSLog(@"fileText=%@", fileText);
}

Output

2020-04-22 21:57:41.726661+0900 EmbedFileSample[10929:2028561] filePath=/private/var/containers/Bundle/Application/83611BD6-C136-477C-A4F7-D229F17EB2EA/EmbedFileSample.app/sample.txt
2020-04-22 21:57:41.727121+0900 EmbedFileSample[10929:2028561] fileText=This is a sample file.