您不能将数据保存在应用程序的主包中,而是必须在文档目录中执行如下操作:
NSArray *paths=NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *plistFilePath = [documentsDirectory stringByAppendingPathComponent:@"Data.plist"];
if([[NSFileManager defaultManager] fileExistsAtPAth:plistFilePath])
{//plist already exits in doc dir so save content in it
NSMutableArray *data = [NSMutableArray arrayWithContentsOfFile:plistFilePath];
NSArray *arrValue = [data objectAtIndex:arrayCounter];
NSString *strValue = [arrValue objectAtIndex:0];
strValue = [strValue stringByAppending:@"hello"]; //change your value here
[[data objectAtIndex:arrayCounter] replaceObjectAtIndex:0 withObject:strValue]; //value replaced
[data writeToFile:plistFilePath atomically:YES];
}
else{ //firstly take content from plist and then write file document directory. it will be executed only once
NSString *plistPath = [[NSBundle mainBundle] pathForResource:@"Data" ofType:@"plist"];
NSMutableArray *data = [NSMutableArray arrayWithContentsOfFile:plistPath];
NSArray *arrValue = [data objectAtIndex:arrayCounter];
NSString *strValue = [arrValue objectAtIndex:0];
strValue = [strValue stringByAppending:@"hello"]; //change your value here
[[data objectAtIndex:arrayCounter] replaceObjectAtIndex:0 withObject:strValue]; //value replaced
[data writeToFile:plistFilePath atomically:YES];
}