iPhone: How to write plist array of dictionary object
Posted
by Alessandro
on Stack Overflow
See other posts from Stack Overflow
or by Alessandro
Published on 2010-04-18T21:45:39Z
Indexed on
2010/04/18
21:53 UTC
Read the original article
Hit count: 1097
Hello, I'm a young Italian developer for the iPhone. I have a plist file (named "Frase") with this structure:
Root Array - Item 0 Dictionary Frase String Preferito Bool - Item 1 Dictionary Frase String Preferito Bool - Item 2 Dictionary Frase String Preferito Bool - Item 3 Dictionary Frase String Preferito Bool exc.
An array that contains many elements dictionary, all the same, consisting of "Frase" (string) and "Preferito" (BOOL).
The variable "indirizzo", increase or decrease the click of the button Next or Back. The application interface:
http://img691.imageshack.us/img691/357/schermata20100418a20331.png
When I click on AddPreferito button, the item "Preferito" must be YES. Subsequently, the array must be updated with the new dictionary.The code:
(void)addpreferito:(id)sender { NSString *plistPath = [[NSBundle mainBundle] pathForResource:@"Frase" ofType:@"plist"]; MSMutableArray *frase = [[NSMutableArray alloc] initWithContentsOfFile:plistPath]; NSMutableDictionary *dictionary = [frase objectAtIndex:indirizzo]; [dictionary setValue: YES forKey:@"Preferito"]; [frase replaceObjectAtIndex:indirizzo withObject:dictionary]; [frase writeToFile:plistPath atomically:YES]; }
Why not work? Thanks Thanks Thanks!
© Stack Overflow or respective owner