title: Dictionary's and plist files
body: <p>I have written some code that pulls info from a plist file and does a couple of things then eventually pops this data into a table.</p>
  
  <p>This all works fine, the problem is I wrote the code pulling the data from a plist file within the resources folder, but the actual file will be created via an action and stored in memory. I need some help on getting my code working when pulling it from the new location.</p>
  
  <p>current working code:</p>
  
  <pre><code>- (void) loadData{
  // Load items
  NSString *error;
  NSPropertyListFormat format;
  NSString *path = [[NSBundle mainBundle] pathForResource:@"CalculatorData" ofType:@"plist"];
  NSData *plistData = [NSData dataWithContentsOfFile:path];
  NSArray *amountData = [NSPropertyListSerialization propertyListFromData:plistData mutabilityOption:NSPropertyListImmutable format:&amp;format errorDescription:&amp;error];
  NSDictionary *amountData = [NSPropertyListSerialization propertyListFromData:plistData mutabilityOption:NSPropertyListImmutable format:&amp;format errorDescription:&amp;error];
  
  if (amountData) {
      self.amounts = [[NSMutableArray alloc] initWithCapacity:[amountData count]];
      result = 0;
      for (NSDictionary *amountsDictionary in amountData) {
  
          [self.amounts addObject:amountsDictionary];
  
          currentNumber = [[amountsDictionary objectForKey:@"Value"] floatValue];
  
          if ([[amountsDictionary objectForKey:@"Type"] isEqualToString:@"Plus"]) {
              result = result + currentNumber;
          } else {
              result = result - currentNumber;
          }
      }
      //Set main amount
      NSString *msg = [NSString stringWithFormat:@"£%.2f",result];
      [lblAmount setText:msg];
  } else {
      UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:@"Why not keep track of your income and expensies? Add new items below." delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
      [alert show];
      [alert release];
  }
  }
  </code></pre>
  
  <p>I think to pull the info from the new file location i need something similar to below, but can't seem to get the output the same as above:</p>
  
  <pre><code>//Get file location
  NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
  NSString *documentsDirectory = [paths objectAtIndex:0];
  NSString *path = [documentsDirectory stringByAppendingPathComponent:@"saveBudget.plist"];
  
  // read it back in with different dictionary variable
  NSMutableDictionary *amountData = [NSMutableDictionary dictionaryWithContentsOfFile:path];
  if(amountData==nil ){
      NSLog(@"failed to retrieve dictionary from disk");
  } else {  
      NSLog(@"%@", amountData);
  }
  </code></pre>
  
  <p>The code creating the plist file is (this also needs a little work, as its currently always overwriting what was done before, when I would like it to add a new array):</p>
  
  <pre><code>-(void) addData {
  
  // create a dictionary to store a fruit's characteristics
  NSMutableDictionary *items = [[NSMutableDictionary alloc] init];
  [items setObject:@"10" forKey:@"Value"];
  [items setObject:@"tester" forKey:@"Description"];
  [items setObject:@"Plus" forKey:@"Type"];
  
  // create a dictionary to store all fruits
  NSMutableDictionary *plist = [[NSMutableDictionary alloc] init];
  [plist setObject:items forKey:@"0"];
  
  //Get file location
  NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
  NSString *documentsDirectory = [paths objectAtIndex:0];
  NSString *path = [documentsDirectory stringByAppendingPathComponent:@"saveBudget.plist"];
  
  // write plist to disk
  [plist writeToFile:path atomically:YES];
  }
  </code></pre>
  
  <p>This also needs a little work as I would like it to be:</p>
  
  <pre><code>    &lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"&gt;
  &lt;plist version="1.0"&gt;
  &lt;array&gt;
      &lt;dict&gt;
          &lt;key&gt;Date&lt;/key&gt;
          &lt;string&gt;27/9/10&lt;/string&gt;
          &lt;key&gt;Value&lt;/key&gt;
          &lt;string&gt;10.97&lt;/string&gt;
          &lt;key&gt;Description&lt;/key&gt;
          &lt;string&gt;PaperRound&lt;/string&gt;
          &lt;key&gt;Type&lt;/key&gt;
          &lt;string&gt;Plus&lt;/string&gt;
      &lt;/dict&gt;
      &lt;dict&gt;
          &lt;key&gt;Date&lt;/key&gt;
          &lt;string&gt;27/9/10&lt;/string&gt;
          &lt;key&gt;Value&lt;/key&gt;
          &lt;string&gt;10.97&lt;/string&gt;
          &lt;key&gt;Description&lt;/key&gt;
          &lt;string&gt;PaperRound&lt;/string&gt;
          &lt;key&gt;Type&lt;/key&gt;
          &lt;string&gt;Plus&lt;/string&gt;
      &lt;/dict&gt;
      &lt;dict&gt;
          &lt;key&gt;Date&lt;/key&gt;
          &lt;string&gt;27/9/10&lt;/string&gt;
          &lt;key&gt;Value&lt;/key&gt;
          &lt;string&gt;10.97&lt;/string&gt;
          &lt;key&gt;Description&lt;/key&gt;
          &lt;string&gt;PaperRound&lt;/string&gt;
          &lt;key&gt;Type&lt;/key&gt;
          &lt;string&gt;Plus&lt;/string&gt;
      &lt;/dict&gt;
      &lt;dict&gt;
          &lt;key&gt;Date&lt;/key&gt;
          &lt;string&gt;27/9/10&lt;/string&gt;
          &lt;key&gt;Value&lt;/key&gt;
          &lt;string&gt;10.97&lt;/string&gt;
          &lt;key&gt;Description&lt;/key&gt;
          &lt;string&gt;PaperRound&lt;/string&gt;
          &lt;key&gt;Type&lt;/key&gt;
          &lt;string&gt;Plus&lt;/string&gt;
      &lt;/dict&gt;
  &lt;/array&gt;
  &lt;/plist&gt;
  </code></pre>
  
  <p>Sorry for the long post but hopefully should be everything that relates.
  Any help on this would be great.</p>