domlao
domlao

Reputation: 16029

How to grab property list file created in Xcode?

I am having a hard time figuring out how to get the property list file that was created using Xcode. I created a property list file using array with NSString members. I want to grab that file and get all the NSString members and save it to a UITextField. But my problem is that I can't see that file. I don't know if I'm looking in the wrong path, or I don't know where the property file is saved.

Upvotes: 1

Views: 1683

Answers (1)

mahboudz
mahboudz

Reputation: 39376

Most likely, if the file was added via Xcode, the file is in your bundle. To open it use:

NSDictionary *plist = [NSDictionary arrayWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"NameOfFile" ofType:@"plist"]];

Run this in the simulator and then look in the Finder, in Library/Application Support/iPhone Simulator/Applications/... to see if you can find the file, open it in and double check it to make sure Xcode added the file.

To make a copy in your Documents folder:

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *path = [documentsDirectory stringByAppendingPathComponent:@"My.plist"];
if (![plist writeToFile:path atomically:YES])
    NSLog(@"not successful in writing the high scores");

Upvotes: 2

Related Questions