I am totally confused while using a plist file.
Can anyone explain me the lifecycle of the .plist file.
If I create a .plist file programmatically and add some data in it.
and if i close my app (completely not deleting it) does my .plist file will get lost and i have to recreate it.?
I have this code
-(void)WriteFileToPlist:(int) num
{
//write everything in the plist
NSString *errorDesc;
NSData *plistData = [NSPropertyListSerialization dataFromPropertyList:strArray format:NSPropertyListXMLFormat_v1_0 errorDescription:&errorDesc];
if (plistData) {
[plistData writeToFile:[self savePathForFile:num] atomically:YES];
}
}
//save the path
-(NSString *) savePathForFile:(int) num
{
NSArray *pathArray =
NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
return [[pathArray objectAtIndex:0] stringByAppendingPathComponent:[NSString stringWithFormat:@"myPlist%d.plist",num]];
}
question is where the file myPlist get stored. closing the app will delete this plist or not.??
It’s simply a file stored on the device. If you save it in the right folder (for example, not a Cache folder) it’ll stay there, just like any other file you can save.