¿Cómo agregar datos en plist? [duplicar]

I have a .plist file. When I write data to plist it does't append but overwrites the previous content.

Aquí está mi código

// get paths from root direcory
NSArray *paths = NSSearchPathForDirectoriesInDomains (NSDocumentDirectory, NSUserDomainMask, YES);
// get documents path
NSString *documentsPath = [paths objectAtIndex:0];
// get the path to our Data/plist file
NSString *plistPath = [documentsPath stringByAppendingPathComponent:@"HistoryList.plist"];

// set the variables to the values in the text fields
NSString *str=[NSString stringWithFormat:@" %@  %@ %@",strname.text,strnum.text,selectfield.text];
self.historyArray = str;

// create dictionary with values in UITextFields
NSDictionary *plistDict = [NSDictionary dictionaryWithObjects: [NSArray arrayWithObjects: historyArray, nil] forKeys:[NSArray arrayWithObjects: @"Name",  nil]];

NSString *error = nil;
// create NSData from dictionary
NSData *plistData = [NSPropertyListSerialization dataFromPropertyList:plistDict format:NSPropertyListXMLFormat_v1_0 errorDescription:&error];

// check is plistData exists
    // write plistData to our Data.plist file
    [plistData writeToFile:plistPath atomically:YES];
    NSLog(@"Error in saveData: %@", error);


How to write data in plist such that it gets appended to previous and does not overwrite?

preguntado el 27 de noviembre de 13 a las 06:11

@Bhumeshwerkatre So close the question rather than just making a comment. -

@user3040536 ipgames.wordpress.com/tutorials/writeread-data-to-plist-file, check the above link may be it will helps you. -

1 Respuestas

  1. Read the .plist file and load as dictionary
  2. modify the dictionary with your new items
  3. save the complete dictionary replacing the old file

respondido 27 nov., 13:07

but how can i do it ?? - user3040536

NSDictionary *dict = [NSDictionary dictionaryWithContentsOfFile: plistPath]; - Traze

how to perform with swift - Karthi Rasu

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.