ios - Sorting data by multiple key values -


i have basic list app 2 entities folder , item many relationship, folder subclass has function called itemsarray() returns items in sorted array creationdate displayed uitableview.

item has 2 properties called date of type nsdate , of type bool called completed. have created function can mark cell item object completed changes cell text color grey.

is there way can sort completed value ? e.g completed value of true or false should separate completed items , sort creationdate.

the end result should completed items @ bottom of uitableview , in order of date non completed items in order of date. if completion higher priority date still orders creationdate

heres current function sort descriptor return array;

func itemsarray() -> [item] {     let sortdescriptor = nssortdescriptor(key: "creationdate", ascending: true)     return checklist.sortedarrayusingdescriptors([sortdescriptor]) as! [item] } 

ps: tried work arounds such when marking completed updating date @ bottom. separates completed items non completed. when unmarking item remains @ bottom isn't long term solution may want change sorting alphabetical order , completion.

you can add nssortdescriptor function:

func itemsarray() -> [item] {     let sortbycompleted = nssortdescriptor(key: "completed", ascending: true)     let sortbycreationdate = nssortdescriptor(key: "creationdate", ascending: true)     return checklist.sortedarrayusingdescriptors([sortbycompleted, sortbycreationdate]) as! [item] } 

play ascending value true first or false first. or swifty way of doing things:

func itemsarray() -> [item] {     return checklist.sort {         if $0.completed == $1.completed {             return $0.creationdate < $1.creationdate         }         return $0.completed < $1.completed     } } 

Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -