title: Implementing a Search History feature in iOS
body: <p>I've got a search page at the moment which will load a list of results for a web-service, but when I return to the search page I would like to '<strong>save</strong>' <strong>whatever was entered</strong> (e.g. 'resto italian') and then display that entry and previous entries into a table view below, like in my following image: </p>
  
  <p><img src="https://i.stack.imgur.com/JdAqY.png" alt="enter image description here"></p>
  
  <p>My plan was to use property list serialization - if there isn't already a list, create a property list called history.plist, and populate it with each search term that is made, and display the nearest ten in the table view like above. </p>
  
  <p><strong>What I've tried:</strong></p>
  
  <pre><code>// should create history.plist
  - (NSString *)dataFilePath {
      NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentationDirectory, NSUserDomainMask, YES);
      NSString *documentsDirectory = [paths objectAtIndex:0];
      return [documentsDirectory stringByAppendingString:@"history.plist"];
  }
  
  /* This is the action for when 'search' is clicked - calls the method above to create 
  a new plist if it's not already created. 
  I then try to display the contents of the of the file in the textfield itself 
  (for testing purposes) but it's not saving/displaying properly at the moment. */
  
  - (IBAction)saveHistory:(id)sender {        
      NSString *filePath = [self dataFilePath];
      if([[NSFileManager defaultManager] fileExistsAtPath:filePath])
      {
         NSArray *array = [[NSArray alloc] initWithContentsOfFile:filePath];
         for (int i = 0; i &lt; (sizeof(array)); i++) {
              UITextField *theField = self.searchHistory;
              theField.text = [NSString stringWithFormat:@"%@", array];
         }
      }        
      UIApplication *app = [UIApplication sharedApplication];
      [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationWillResignActive:) name:UIApplicationWillResignActiveNotification object:app];        
  }
  </code></pre>
  
  <p>Any links to tutorials attempting to do this, suggestions towards what I should do, or improvements to what I have would be greatly appreciated.</p>