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
.
When you add files to the Xcode project, Xcode add them to Copy Bundle Resources
in the Build Phases
of project setting automatically.
Build project and open application bundle by Finder. You can see copied file in it.
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.