I'm trying to sort an array as laid out in the accepted answer to this question, but am running into the problem which Isuru mentions in the comments on that answer. Namely, the code which should sort the array by the entity's "date" attribute brings the compiler complaint "could not find member 'date'"
Here is the NSManagedObject subclass describing the entity:
import Foundation
import CoreData
@objc(Entry)
class Entry: NSManagedObject {
@NSManaged var date: NSDate
@NSManaged var reflections: AnyObject
@NSManaged var contactComment: NSSet
@NSManaged var person: NSSet
override func awakeFromInsert() {
let now:NSDate = NSDate()
self.date = now;
}
}
And here is the code which tries to sort the array:
lazy var entries:[Entry] = {
var days:[Entry] = self.managedObjectContext!.requestEntity("Entry")as [Entry]
days.sort({$0.date < $1.date})
var today:Entry = days.last!
println(today.date)
return days
}()
Note that in the latter part of that code, I am able to access and log the "date" property for one of the entries, and the Compiler doesn't have a problem with it.
Is my syntax for sorting correct? Is there another issue with this code I'm not seeing?