简体   繁体   中英

create simple txt file and read from it objective c

I want to create mock implementation of server. I have several json-files.

I want to add these files to the xcode project, and then read from them in the application.

In android we have assets folder. And we can place there files, and they will be installed with the application.

Is there any asset folder in ios to store files, and how to read files from there?

In iOS App Bundle is the main directory. If you put your file there you can read as such:

NSString *filePath = [[NSBundle mainBundle] pathForResource:@"myFile" ofType:@"txt"];
NSString *testString = [NSString stringWithContentsOfFile:filePath encoding:NSUTF8StringEncoding error:nil];
NSLog(@"%@",testString); 

This will read file myFile.txt

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM