I have a StateArray.plist set up with 50 dictionary entries each containing a string with the name of the state and a number 0. What I want to be able to do is change the 0 to a 1 through a segmented control and save the updated plist. The code I have is below and won't save the changed number.
-(void) viewWillAppear: (BOOL) animated
{
[super viewWillAppear:animated];
nameOfStateTextField.text = [states objectForKey:NAME_KEY];
}
//segmented control
-(IBAction)visitedChanged
{
selectedVisited = visitedSegmentedControl.selectedSegmentIndex;
}
-(IBAction)saveButton
{
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *path = [documentsDirectory stringByAppendingPathComponent:@"StateArray.plist"];
[states setValue:selectedVisited forKey:THERE_KEY];
[states writeToFile:path atomically:YES];
}
The changed segmented control value should end up as the new THERE_KEY and be written to the Documents directory and saved. What could be wrong here?