title: Replace item in NSMutablearray
body: <p>I have an NSMutablearray that I have data saved to. Data is input on my main ViewController. When you tap on a saved item, the SecondViewController has a textfield that the data entry is loaded into in order to be edited. I want to be able to edit that item and then save it back to the array.</p>
  
  <p>I am fairly new to Objective-C / Cocoa Touch so please go easy on me.</p>
  
  <pre><code>- (ToDoItem *) updateToDoItem: (ToDoItem *) todoitem {
      NSLog(@"ToDoItemSvc.updateToDoItem: %@", [todoitem description]);
      NSMutableArray *toDoItems = [NSMutableArray array];
          for (NSString *todoitem in toDoItems) {
              if ([[ToDoItem] isEqualToString:toDoItems]) {
          [toDoItems replaceObjectAtIndex:todoitem];
      }
  }
  </code></pre>
  
  <p>I know this isnt completely correct and may be completely off base but Im hoping I am moving in the right direction with this.</p>
  
  <h3>EDIT</h3>
  
  <p>Here is my ToDoItemSvcArchive.m file</p>
  
  <pre><code>#import "ToDoItemSvcArchive.h"
  
  @implementation ToDoItemSvcArchive
  
  NSString *filePath;
  
  NSMutableArray *toDoItems;
  
  - (id) init {
      NSArray *dirPaths =
      NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,
                                      NSUserDomainMask, YES);
      NSString *docsDir = [dirPaths objectAtIndex:0];
      filePath = [[NSString alloc] initWithString: [docsDir
                                                     stringByAppendingPathComponent: @"ToDoItems.archive"]];
      [self readArchive];
      return self;
  }
  
      - (void) readArchive {
      NSFileManager *filemgr = [NSFileManager defaultManager];
      if ([filemgr fileExistsAtPath: filePath])
  {
          toDoItems = [NSKeyedUnarchiver unarchiveObjectWithFile: filePath];
  }
      else
  {
          toDoItems = [NSMutableArray array];
  }
  }
  
  - (void) writeArchive {
      [NSKeyedArchiver archiveRootObject:toDoItems toFile:filePath];
  
  }
  
  - (ToDoItem *) createToDoItem: (ToDoItem *) todoitem {
      NSLog(@"ToDoItemSvc.createToDoItem: %@", [todoitem description]);
  
      [toDoItems addObject:todoitem];
      [self writeArchive];
  
      return todoitem;
  }
  
  
  - (NSMutableArray *) retrieveAllToDoItems {
      return toDoItems;
  }
  
  - (ToDoItem *) updateToDoItem: (ToDoItem *) todoitem {
      NSLog(@"ToDoItemSvc.updateToDoItem: %@", [todoitem description]);
      NSMutableArray *toDoItems = [NSMutableArray array];
      for (NSString *todoitem in toDoItems) {
          if ([[ToDoItem] isEqualToString:toDoItems]) {
              [toDoItems replaceObjectAtIndex:todoitem];
          }
      }
  
     // return todoitem;
  }
  
  - (ToDoItem *) deleteToDoItem: (ToDoItem *) todoitem {
      NSLog(@"ToDoItemSvc.deleteToDoItem: %@", [todoitem description]);
  
      [toDoItems removeObject:todoitem];
     [self writeArchive];
  
      return todoitem;
  }
  
  @end
  </code></pre>
  
  <h3>EDIT</h3>
  
  <p>I guess what I dont really understand is how to get the actual index of the object that needs to be replaced.</p>
  
  <h3>Edit</h3>
  
  <p>I think this is better</p>
  
  <pre><code>- (ToDoItem *) updateToDoItem: (ToDoItem *) todoitem {
      NSLog(@"ToDoItemSvc.updateToDoItem: %@", [todoitem description]);
      NSUInteger index = [toDoItems indexOfObject:todoitem];
      [toDoItems replaceObjectAtIndex:0 withObject:todoitem];
  
      return todoitem;
  }
  </code></pre>
  
  <p>Im still not sure how to specify the correct index.</p>