title: Core Data sort descriptor with NSDate, iOS with Swift
body: <p>I am trying to filter core data objects depending on a date attribute.</p>
  
  <p>This is my current code:</p>
  
  <pre><code>func getFetchedResultController(selectedEntity: NSString){
  
      let appDelegate : AppDelegate = UIApplication.sharedApplication().delegate as! AppDelegate
      let managedObjectContext: NSManagedObjectContext = appDelegate.managedObjectContext!
  
      let fetchRequest = NSFetchRequest()
  
      let entity = NSEntityDescription.entityForName(selectedEntity as String, inManagedObjectContext: managedObjectContext)
  
      fetchRequest.entity = entity
  
      fetchRequest.fetchBatchSize = 20
  
      let date = NSDate()
  
      let sectionSortDescriptor = NSSortDescriptor(key: "timeStamp &lt; %@",date)
  
      let sortDescriptors = [sectionSortDescriptor] //, secondSortDescriptor]
  
      fetchRequest.sortDescriptors = sortDescriptors
  
      let aFetchedResultsController = NSFetchedResultsController(fetchRequest: fetchRequest, managedObjectContext: managedObjectContext, sectionNameKeyPath: nil, cacheName: nil)
  
      aFetchedResultsController.delegate = self
      self.fetchedResultsController = aFetchedResultsController
  
      var error: NSError? = nil
      if !self.fetchedResultsController.performFetch(&amp;error) {
          abort()
      }
  
   print(fetchedResultsController.fetchedObjects?.count ?? 0)
  }
  </code></pre>
  
  <p>But I get an error at line: </p>
  
  <pre><code>let sectionSortDescriptor = NSSortDescriptor(key: "timeStamp &lt; %@",date)
  </code></pre>
  
  <p>How should I change this sort descriptor to get the objects that have an older or a newer date on the "timeStamp" attribute?</p>
  
  <p>Thank you.</p>