ios - Swift CoreDate Fetch by Date and Time Stored as String and Sort -


in coredate table, storing date , time string in below format , have specific reason storing string.

static let datefmtval = "dd-mm-yyyy"; static let timefmtval = "hh:mm a"; 

now while fetching want sort converting string date , time , sort display in tableview, row newer ones come on top

let datesortvar = nssortdescriptor(key: datecol, ascending: false) let timesortvar = nssortdescriptor(key: timecol, ascending: false) fetchedresultscontroller.fetchrequest.sortdescriptors = [datesortvar, timesortvar] 

in android, using sqlite got solution :

sqlqryvar = "select * " + namtblval +                         " order strftime('%d-%m-%y %h:%i'," + datecol + "|| ' ' ||" + timecol + ") desc;"; 

so kindly me same in swift

you can add computed property of type date coredata object (in subclass ), conversions there , pass sort descriptor , same behavior in android app, take consideration different in ios android converting string date in ios slow!!! , allocating several dateformatters expensive (but can use 1 conversions). if don't have lot of dates work , anyway if want right sorted data have convert @ point. solution without converting date considering use other format date column i.e "yyyy-mm-dd" string sort match date.


Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -