Core Data sort descriptor with NSDate, iOS with Swift
To fetch all objects satisfying some condition you don't need a sort descriptor but a predicate, for example:
let predicate = NSPredicate(format: "timeStamp < %@", date)
fetchRequest.predicate = predicate
You need a sort descriptor to get the objects in a specified order, for example:
let sectionSortDescriptor = NSSortDescriptor(key: "timeStamp", ascending: true)
let sortDescriptors = [sectionSortDescriptor]
fetchRequest.sortDescriptors = sortDescriptors
Swift 3.0 This works with no problem for me
let fec:NSFetchRequest = YourEntity.fetchRequest()
let sortDescriptor = NSSortDescriptor(key: "type", ascending: true)
fec.sortDescriptors = [sortDescriptor]
let items = try! context.fetch(fec)