I am trying to filter the main data objects based on a date attribute.
This is my current 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 < %@",date) let sortDescriptors = [sectionSortDescriptor]
But I get an error message:
let sectionSortDescriptor = NSSortDescriptor(key: "timeStamp < %@",date)
How do I change this sort descriptor to get objects with an older or newer date in the "TimeStamp" attribute?
Thanks.
ios swift core-data
mvasco
source share