Morrowless
Morrowless

Reputation: 6958

Build & Run: plist is not getting updated

I have a plist in my resource bundle which I copy by folder reference. For some reason, my edited & saved (in Xcode) plist is not getting copied/updated until I delete the app. Otherwise the old plist (before editing) is copied over, even though I delete the app. Is data being left over?

The plist is edited quite often, so debugging is very time-consuming this way. How can I make sure the plist is copied properly?

Upvotes: 5

Views: 2382

Answers (2)

Andriko13
Andriko13

Reputation: 990

This is a laaate answer; but hey, the OP did not mark a correct answer, so here is my solution. I created two property lists. The first one is debugging information, like constant numbers, strings and booleans. I called this property list SETTINGS.plist. My other plist is the one that I use to save game data. Since the SETTINGS plist is the one I update through the xcode interface, I update it every time I run the app.

-(void)setUpPlist{

listPath = [[self docsDir] stringByAppendingPathComponent:@"SETTINGS.plist"];

if (![[NSFileManager defaultManager] fileExistsAtPath:listPath]) {
    [[NSFileManager defaultManager] copyItemAtPath:[[NSBundle mainBundle] pathForResource:@"SETTINGS" ofType:@"plist"] toPath:listPath error:nil];

}
else {
    [[NSFileManager defaultManager] removeItemAtPath:listPath error:nil];
    [[NSFileManager defaultManager] copyItemAtPath:[[NSBundle mainBundle] pathForResource:@"SETTINGS" ofType:@"plist"] toPath:listPath error:nil];
}

savedData = [NSMutableDictionary dictionaryWithContentsOfFile:listPath];
}

-(NSString *)docsDir{
return [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
}

Here, listPath is of NSString type and savedDate is of NSMutableDictionary type. Hope this helps.

Upvotes: 0

Saurabh
Saurabh

Reputation: 22873

Are you copying the plist file in Documents folder? if you are copying that then you must delete the app from iPhone simulator every time you launch the app.

You can also do one thing.. you can copy the file in documents folder every time you launch the app. Because the document folder's content can only be delete by deleting the app from simulator/device.

Then there is no need to restart the simulator/device and xcode.

Upvotes: 1

Related Questions