The bottom line is to write an extension that sorts an array of NSManagedObjects
by dateCreated
. Or, to go from this:
let materialArray = (Array(quote.materials!) as? [Materials])?.sorted(by: { $0.dateCreated?.compare($1.dateCreated!) == .orderedDescending })
to this:
let materialArray = (Array(quote.materials!) as? [Materials])?.sortedByDate
All of my entities inherit a created date, including the one above called Materials
. I'd like to write an extension to sort by that date but I'm not sure what to extend...or how. So far I have:
extension Materials
{
func sortedByDate() -> [Materials]
{
return self.sorted(by: { $0.dateCreated?.compare($1.dateCreated!) == .orderedDescending })
}
}
The biggest problem is the error stating that Materials
has no member 'sorted
'. Making this extension work with all entities that inherit dateCreated
is the ultimate goal. Thank you.