title: How to load/save data in NSMutableArray
body: <p>Here is my <code>mainAppDelegate.h</code>:</p>
  
  <pre><code>#import &lt;UIKit/UIKit.h&gt;
  
  @interface mainAppDelegate : UIResponder &lt;UIApplicationDelegate&gt;
  
  @property (strong, nonatomic) UIWindow *window;
  @property NSMutableArray *toDoItems;
  
  @end
  </code></pre>
  
  <p>and my <code>mainAppDelegate.m</code>:</p>
  
  <pre><code>#import "mainAppDelegate.h"
  
  @implementation mainAppDelegate
  
  - (void)applicationWillTerminate:(UIApplication *)application
  {
      NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
      NSString *documentsDirectory = [paths objectAtIndex:0];
      NSString *filePath = [documentsDirectory stringByAppendingPathComponent:@"toDoItems.plist"];
      [self.toDoItems writeToFile:filePath atomically:TRUE];
  }
  @end
  </code></pre>
  
  <p>I have another file, <code>XYZToDoListViewController.m</code> with the code:</p>
  
  <pre><code>#import "XYZToDoListViewController.h"
  #import "XYZToDoItem.h"
  #import "XYZAddItemViewController.h"
  
  @interface XYZToDoListViewController ()
  @property NSMutableArray *toDoItems;
  @end
  
  @implementation XYZToDoListViewController
  
  - (IBAction)unwindToList:(UIStoryboardSegue *)segue
  {
      XYZAddItemViewController *source = [segue sourceViewController];
      XYZToDoItem *item = source.toDoItem;
      if (item != nil) {
          [self.toDoItems addObject:item];
          [self.tableView reloadData];
      }
  }
  
  - (IBAction)clearData:(UIBarButtonItem *)sender;
  {
      [self.toDoItems removeAllObjects];
      [self.tableView reloadData];
  }
  
  - (id)initWithStyle:(UITableViewStyle)style
  {
  self = [super initWithStyle:style];
  if (self) {
  
  }
  return self;
  }
  
  - (void)viewDidLoad
  {
      [super viewDidLoad];
      self.toDoItems = [[NSMutableArray alloc] init];
      self.navigationController.view.backgroundColor =
      [UIColor colorWithPatternImage:[UIImage imageNamed:@"bg_full.png"]];
      self.tableView.backgroundColor = [UIColor clearColor];
      self.tableView.contentInset = UIEdgeInsetsMake(-35, 0, -35, 0);
  }
  @end
  </code></pre>
  
  <p>This is at least what I think is relevant. My basic framework is something I followed from <a href="https://developer.apple.com/library/ios/referencelibrary/GettingStarted/RoadMapiOS/ThirdTutorial.html#//apple_ref/doc/uid/TP40011343-CH10-SW1" rel="nofollow">this tutorial.</a> So as you can see I have an NSMutableArray named .toDoItems. and I want it to remember the list when I exit the application (not just minimizing it; it does that already. I think I have the code which is saving the data, but what do I use to check if the file exists, and if so, display it?
  And would this affect my <code>clearData</code> method when the app resumes as well?</p>