title: How to search NSMutableArray with UISearchBar?
body: <p>I've searched many places but could not find the answer, so I decided to set my own question.</p>
  
  <p>I populate a UITableView with data from JSON. My data structure is like this:</p>
  
  <pre><code>NSMutableArray* studentList = [(NSDictionary*)[responseString JSONValue] objectForKey:@"StudentList"];
  </code></pre>
  
  <p>JSON:</p>
  
  <pre><code>{
  "StudentList":[
      {
        "StudentID":"08DH11039",
        "StudentFirstName":"Nguyen Lam",
        "StudentLastName":"Binhh"
      },
      {
        "StudentID":"08DH11163",
        "StudentFirstName":"Nguyen Minh",
        "StudentLastName":"Duc"
      },
      {
        "StudentID":"08DH11038",
        "StudentFirstName":"Nguyen Bao",
        "StudentLastName":"Khuyen"
      },
      {
        "StudentID":"08DH11037",
        "StudentFirstName":"Nguyen Tran Duy",
        "StudentLastName":"Phuong"
      }
    ]
  }
  </code></pre>
  
  <p>Add data to UITableView:    </p>
  
  <pre><code>- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
          static NSString *CellIdentifier = @"Cell";
          UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
          if (cell == nil) {
              cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
          }
          NSDictionary *student = [studentList objectAtIndex:indexPath.row];
          cell.textLabel.text = [NSString stringWithFormat:@"%d. %@ %@", indexPath.row+1, [student objectForKey:@"StudentFirstName"], [student objectForKey:@"StudentLastName"]];
          cell.textLabel.font = [UIFont fontWithName:@"Helvetica" size:15];
          cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
          return cell;
      }
  </code></pre>
  
  <p>I also add a UISearchBar but it didn't work:</p>
  
  <pre><code>- (BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchString:(NSString *)searchString
  {
      [searchData removeAllObjects];
  
      NSArray *student; 
  
      for(student in studentListCopy) //take the n group (eg. group1, group2, group3)
      {
          NSLog(@"%@", student);
          NSMutableArray *newGroup = [[NSMutableArray alloc] init];
          NSString *element;
  
          for(element in student)
              NSRange range = [element rangeOfString:searchString
                                             options:NSCaseInsensitiveSearch];
  
              if (range.length &gt; 0) { //if the substring match
                  [newGroup addObject:element]; //add the element to group
              }
          }
  
          if ([newGroup count] &gt; 0) {
              [searchData addObject:newGroup];
          }
      }
  
      return YES;
  }
  </code></pre>
  
  <p>Please help me to get it work. I want to search FirstName or LastName, which are displayed in TableView. </p>
  
  <p>I'm new to iOS programming. Thank you very much.</p>