ios - Sorting array gives me error -


i have array of structs. in struct have 2 nsdate objects: prop1 , prop2. i'm trying sort prop1 newest oldest date/time. , want prop2 ordered based on prop1. (i want vice versa.)

struct item {     let prop1 : nsdate     let prop2 : nsdate }  var myitem = [item]()  myitem.insert(item(prop1: mydatesecond, prop2: anotherdatesecond), atindex: 0) myitem.insert(item(prop1: mydatethird, prop2: anotherdatethird), atindex: 0) myitem.insert(item(prop1: mydatefirst, prop2: anotherdatefirst), atindex: 0)  myitem.sort { $0.prop1 < $1.prop1 } 

at last line of code, following error:

cannot invoke 'sort' argument list of type '((_, _) -> _)'

what doing wrong, , how can fix it?

when comparing 2 dates have use nsdate method compare:

struct item {     let prop1 : nsdate     let prop2 : nsdate }  var myitem = [item]()  myitem.insert(item(prop1: mydatesecond, prop2: anotherdatesecond), atindex: 0) myitem.insert(item(prop1: mydatethird, prop2: anotherdatethird), atindex: 0) myitem.insert(item(prop1: mydatefirst, prop2: anotherdatefirst), atindex: 0)  myitem.sort{$0.prop1.compare($1.prop1) == nscomparisonresult.orderedascending} 

Comments

Popular posts from this blog

c# - Binding a comma separated list to a List<int> in asp.net web api -

Delphi 7 and decode UTF-8 base64 -

html - Is there any way to exclude a single element from the style? (Bootstrap) -