Я использую plist
в своем приложении, я могу добавить значения в plist
и все работает нормально. Но мне нужно только 3 значения, которые должны быть добавлены к plist
, а затем при попытке чтобы добавить больше значений, следует перезаписать предыдущие три значения .. одно за последующим добавлением ..
Вот мой код, который добавляет много значений x:
-(void) myplist :(id) sender
{
NSLog(@"mylist Clicked");
NSMutableArray *array = [[NSMutableArray alloc] init];
// get paths from root direcory
NSArray *paths = NSSearchPathForDirectoriesInDomains (NSDocumentDirectory, NSUserDomainMask, YES);
// get documents path
NSString *documentsPath = [paths objectAtIndex:0];
NSString *docsDir = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES) objectAtIndex:0]; // get the path to our Data/plist file
NSLog(docsDir);
NSString *plistPath = [docsDir stringByAppendingPathComponent:@"Data.plist"];
//This copies objects of plist to array if there is one
[array addObjectsFromArray:[NSArray arrayWithContentsOfFile:plistPath]];
[array addObject:searchLabel.text];
// This writes the array to a plist file. If this file does not already exist, it creates a new one.
[array writeToFile:plistPath atomically: TRUE];
}