tags:

views:

30

answers:

1

I'm trying to write Boolean to a plist file. My code is:

 NSString *filePath = [self dataFilePath];
 if (filePath) 
 {
  if (check) 
  {
   NSLog(@"Clear");
   [item setObject:[NSNumber numberWithBool:NO] forKey:@"check"];
   [item writeToFile:filePath atomically: YES];
  }else{
   NSLog(@"Green");
   [item setObject:[NSNumber numberWithBool:YES] forKey:@"check"];
   [item writeToFile:filePath atomically: YES];
  }
  NSLog([[NSString alloc] initWithContentsOfFile:filePath]);
 }else{
  NSLog(@"write file was not found");
 }

My filePath is:

- (NSString *)dataFilePath 
{
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];
    return [documentsDirectory stringByAppendingPathComponent:@"CheckMark.plist"];
}

I load my array with:

- (void)viewDidLoad
{
 NSString *filePath = [self dataFilePath];
 NSLog(@"%@", filePath);

 if (![[NSFileManager defaultManager] fileExistsAtPath:filePath])
 {
  NSString *myPathInfo = [[NSBundle mainBundle] pathForResource:@"CheckMark" ofType:@"plist"];
  NSFileManager *fileManager = [NSFileManager defaultManager];
  [fileManager copyItemAtPath:myPathInfo toPath:filePath error:NULL];
 }    

 // load our data from a plist file inside our app bundle
 self.dataArray = [NSMutableArray arrayWithContentsOfFile:filePath];
 NSLog([[NSString alloc] initWithContentsOfFile:filePath]);
 NSLog(@"%@", filePath);
 NSLog(@"read dataArray");

Every thing works fine, except when I look at the plist file, nothing changes. I'm writing the plist file to my Documents directory.

Thanks for any help you can give me.

A: 

Remember that you need to be using an NSMutableDictionary to be able to set values.

Alexsander Akers
And that a dictionary is not an array, so trying to load a dictionary plist using NSMutableArray is not going to give reliable (if usable at all) results.
Peter Hosey