swift 模型数组 按照某一属性重新排序
// 按照时间降序排列
let sortedData = self.data.sorted { (model1, model2) -> Bool in
let result = (model1 as! DMRecordModel).createTime?.compare((model2 as! DMRecordModel).createTime!)
// 是否升序
if result == ComparisonResult.orderedAscending {
return false
}else if result == ComparisonResult.orderedDescending {
return true
}else {
return true
}
}
网友评论