What is the correct filepath to store a plist on the device.
I read this in a tutorial
which will work for the computer, would like to know the file location for the device.
// write xml representation of dictionary to a file
[d开发者_JAVA技巧ictionary writeToFile:@"/Users/henrik/Sites/foo.plist" atomically:NO];
I currently try to write to the filepath that I read from
NSString *filepath = [[NSBundle mainBundle]
pathForResource:@"UserAdded" ofType:@"plist"];
userAddedQuotes = [[NSMutableArray alloc] initWithContentsOfFile:filepath];
as follows
[userAddedQuotes addObject:temp];
[userAddedQuotes writeToFile:filepath atomically: NO];
The array gets updated in the runtime, but doesnt get saved to the plist.
You cannot write to any file inside your application bundle (including your resource directory). If you want to write a file you should write it your apps Documents or Library folder, depending on what the file is. For example:
NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
Will return the an array of paths, the first of which is your documents directory.
精彩评论