objective c - Default files in iOS application sandbox -


I am making a quiz app for iPhone I store all queries in a NSArray Which is opened every time the app is loaded with the .xml file. This file will be the same in all "instances" of the app, and it will not be ever changed by the user.

I can work hard with all the questions with code, but I found it more elegant to put it in a file which is easily edited by any text editor.

But how do I copy the app to the "example" of the app? That file should be bundled with the rest files

This is the code (in app representative) so far.

  NSArray * DocumentPaths = NSSearchPathForDirectoriesInDomains (NSDocumentDirectory, NSUserDomainMask, yes); NSString * path = document path [0]; Path = [path stringbapping padding pump: @ "question. Archive"]; NSArray * fileQuestions = [[NSArray alloc] initWithContentsOfFile: Path]; If (! FileQuestions) {// code to add three default questions ... [fileQuestions writeToFile: path atom: yes]; } // Here the "File Question" changes in the examples of my question class  

There is no need to try to store the file in the directory of the document. Just store it in the right app bundle, it works just like an image file, a sound file, or any other resource. Make a file part of the project; Make sure this is part of the app target , so that it will be copied to the app bundle as part of the build process. In the running app, get your path with [[NSBundle mainBundle] pathForResource: ofType:] , and read it as any file of this type.


Comments

Popular posts from this blog

import - Python ImportError: No module named wmi -

Editing Python Class in Shell and SQLAlchemy -

c# - MySQL Parameterized Select Query joining tables issue -