Can someone help me to sort list of my custom objects by multiple parameters.
I want to sort it by date1 and date2 and optionally b all three properties but whatever I try it fails :(
My object:
class MyObject : NSManagedObject{
@NSManaged var date1:NSDate
@NSManaged var date2:NSDate
@NSManaged var key:Int
}
This is my failed tries to sort list of those objects:
var sortedArray1 = sorted(unorderedList, { (o1: MyObject, o2: MyObject) -> Bool in{
return o1.date1 == o2.date1 ? (o1.date2 < o2.date2) : (o1.date1 < o2.date1)
}
var sortedArray2 = sorted(unorderedList, { (o1: MyObject, o2: MyObject) -> Bool in
return (o1.date1.compare(o2.date1) == NSComparisonResult.OrderedAscending) == (o1.date1.compare(o2.date1) == NSComparisonResult.OrderedAscending) ? (o1.date2.compare(o2.date2) == NSComparisonResult.OrderedAscending) : (o1.date1.compare(o2.date1) == NSComparisonResult.OrderedAscending))
});
date1anddate2are date with time. This is some from and to properties. I need to sort list by those two properties to get something like like:04:00to05:00, 04:00to05:30etc. Andkeyis simple1,2,3...but that key can also benilso primary sorting should be bydateproperties.keyso just by dates how can I sort this?