Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I clear the data in a plist created in Xcode?

I have been using a plist to store data in my app. I have been able to write and read from the plist with no problem. I created this plist in Xcode, adding the rows of numbers, dictionaries, and arrays myself. However, I would like to be able to reset the plist to the original state, and there must be an easier way to do this than writing a 0 or nil value to every entry in the plist. So what is the easiest way to reset the plist to its initial default state?

like image 759
gurooj Avatar asked Jan 23 '12 22:01

gurooj


People also ask

How do I edit Info plist on Mac?

plist file. If you need to edit these items, Control-click (or right-click) Info. plist in the sidebar and select Edit Manually. This allows you to add or edit items in raw XML format.

How do I open Info plist on Mac?

Info. plist - The primary property list for Mac OS X applications, located in the /​Contents/​ directory of an . APP bundle. To view this file, right-click an application file, select "Show Package Contents," and open the Contents folder.

What is plist XCode?

The plist is a special file that configures your mobile app, telling it how to run. Every iOS app uses an Info.


2 Answers

The simplest thing would be to delete the file using NSFileManager, like this:

[[NSFileManager defaultManager] removeItemAtPath:plistPath error:NULL];

Or if you don't want to do that, assuming the plist is a dictionary, just load the one from your application bundle and then overwrite the one in your documents, like this:

NSDictionary *originalPlist = [NSDictionary dictionaryWithContentsOfFile:bundleFile];
[originalPlist writeToFile:documentsFile atomically:YES];

Which will overwrite the saved file with the original file.

like image 70
Nick Lockwood Avatar answered Oct 20 '22 00:10

Nick Lockwood


 NSFileManager *fileManager = [NSFileManager defaultManager];
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];
    NSString *fullPath = [documentsDirectory stringByAppendingPathComponent:@"mobile-watchlist.plist"];
    [fileManager removeItemAtPath: fullPath error:NULL];
like image 28
Vijay Maurya Avatar answered Oct 19 '22 22:10

Vijay Maurya