How to create a plist file in xcode 4.3.2

I am trying to create my own plist file to be used in my application, I am using apple docs as refrence for this.

However, I read that if you create your own plist, you need to put it in the resources folder in your app build. The problem is I don't have a resource folder in my assembly ... so I'm confused, what should I do? .. I read this answere guys here , it says it's fine to just put the plist file in the supporting folder Files .. is this ok with the plist read and write?

+3


source to share


2 answers


You can put this plist file anywhere. It is important to copy it into a bunch. Therefore, to make sure of this check project settings>build phases>copy bundle resources



You can open the project settings by left clicking on the project in the project navigator.

+3


source


To read and write for reproduction, it's best to copy it to the document root if you want to access it through a bundle that doesn't have write permission. I have provided a snapshot of the code here and how you can do this.



NSError *err;
NSFileManager *fileManager = [NSFileManager defaultManager];
//getting the path to document directory for the file
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentDir = [paths objectAtIndex:0];
NSString *path = [documentDir stringByAppendingPathComponent:@"YourFile.plist"];

//checking to see of the file already exist
if(![fileManager fileExistsAtPath:path])
{
    //if doesnt exist get the the file path from bindle
    NSString *correctPath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"YourFile.plist"];
    //copy the file from bundle to document dir
    [fileManager copyItemAtPath:correctPath toPath:path error:&err];      
}

      

+5


source







All Articles