iPhone: How to write plist array of dictionary object
- by Alessandro
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!