i already using plist file to store my data and it really works for both read and write data. now how do i delete my old SaveData.plist file inside my iphone device? because when i remove it from xcode and add new one with same name file (SaveData.plist) and run it in my device, my old data is still inside.
i add my SaveData.plist using this code
NSError *error;
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *path = [documentsDirectory stringByAppendingPathComponent:@"SaveData.plist"];
NSFileManager *fileManager = [NSFileManager defaultManager];
if (![fileManager fileExistsAtPath: path])
{
NSString *bundle = [[NSBundle mainBundle] pathForResource:@"SaveData" ofType:@"plist"];
[fileManager copyItemAtPath:bundle toPath: path error:&error];
}
NSMutableDictionary *data = [[NSMutableDictionary alloc] initWithContentsOfFile: path];
NSMutableDictionary *savedStock = [[NSMutableDictionary alloc] initWithContentsOfFile: path];
Thank you.
If there is an old version, the
ifstatement (if the file is already there):causes it not to be copied to the documents folder.
You could delete the file in the documents folder first:
You could also think about loading the content of the old file first, so that you can migrate the saved data.