In Swift 2.0, how would you go about sorting an array of custom objects by a property? I know in Swift 1.2, this was done using sorted() and sort(). However, these methods no longer work in Xcode 7 beta 4. Thanks!
For example:
class MyObject: NSObject {
var myDate : NSDate
}
...
let myObject1 : MyObject = MyObject() //same thing for myObject2, myObject3
var myArray : [MyObject] = [myObject1, myObject2, myObject3]
//now, I want to sort myArray by the myDate property of MyObject.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…