title: filter NSFetchedResultsController result swift 2
body: <p>I want automatic updates on tableview..For that i have used <code>NSFetchedResultsController</code>as</p>
  
  <pre><code>lazy var fetchedResultsController: NSFetchedResultsController = {
      // Initialize Fetch Request
      let fetchRequest = NSFetchRequest(entityName: "Student")
  
      // Add Sort Descriptors
      let sortDescriptor = NSSortDescriptor(key: "grade", ascending: true)
      fetchRequest.sortDescriptors = [sortDescriptor]
  
      // Initialize Fetched Results Controller
      let fetchedResultsController = NSFetchedResultsController(fetchRequest: fetchRequest, managedObjectContext: self.managedObjectContext, sectionNameKeyPath: nil, cacheName: nil)
  
      // Configure Fetched Results Controller
      fetchedResultsController.delegate = self
  
      return fetchedResultsController
  }()
  </code></pre>
  
  <p>But i have to filter the results after loading as of user selection as..</p>
  
  <pre><code>  @IBAction func onSegmentValueChanged(sender: UISegmentedControl)
      {
          if sender.selectedSegmentIndex == 0{
  
              //filter by grade
              let fetchRequest = NSFetchRequest(entityName: "Student")
              let sortDescriptor = NSSortDescriptor(key: "grade", ascending: true)
              fetchRequest.sortDescriptors = [sortDescriptor]
              let filterfetchResultsController = NSFetchedResultsController(fetchRequest: fetchRequest, managedObjectContext: self.managedObjectContext, sectionNameKeyPath: nil, cacheName: nil)
              let predicate = NSPredicate(format: "address = %@","Russia")
              filterfetchResultsController.fetchRequest.predicate = predicate
              self.tableView.reloadData()
  
          }else{
  
              let fetchRequest = NSFetchRequest(entityName: "Student")
              let sortDescriptor = NSSortDescriptor(key: "grade", ascending: true)
              fetchRequest.sortDescriptors = [sortDescriptor]
              let filterfetchResultsController = NSFetchedResultsController(fetchRequest: fetchRequest, managedObjectContext: self.managedObjectContext, sectionNameKeyPath: nil, cacheName: nil)
              let predicate = NSPredicate(format: "grade = %d",10)
              filterfetchResultsController.fetchRequest.predicate = predicate
              self.tableView.reloadData()
  
  
          }
  
      }
  </code></pre>
  
  <p>This however reload the tableView but data is not filtered.how do i solve this problem?<a href="https://drive.google.com/file/d/0B6dTvD1JbkgBbUtQb0tTLTZaZVE/view?usp=sharing" rel="nofollow">This</a> is the demo project i am working on.Or should i use the normal way passing the results and reloading tableView as of normal way to solve this problem?</p>