开发者

Variables to access the "copy bundle resources" xcode build phase files?

开发者 https://www.devze.com 2023-04-03 13:02 出处:网络
I have a few .txt files my app accesses and gets data from. The way I understand it, using my project\'s copy bundle resources build phase will correctly install these files into the Apple-mandated开

I have a few .txt files my app accesses and gets data from.

The way I understand it, using my project's copy bundle resources build phase will correctly install these files into the Apple-mandated开发者_开发问答 directories when the app is run on the user's computer.

Again, as I understand it, this is all I need to do to make the .txt files legal for the Mac Apple Store. Please correct me if I'm wrong.

So, I'm doing the above step. The .txt files are added to the project and to the build step.

Once the app is running, how do I open those files? How do I get the file path?

I'm looking for a standard filepath like: @"~/Library/<app-identifier>/filename.txt>"

Does a list of such special file paths exist?


You should use one of the NSBundle methods. The most basic is:

NSString *path = [[NSBundle mainBundle] pathForResource:@"filename"
                                                 ofType:@"txt"];

Have a look at the NSBundle Class Reference for methods where you can specify subdirectories and how to get other bundles than the main bundle.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号