ios - Prepend multiple data to beginning of Core Data (Swift) -
could give guidance on how prepend newly ingested data core data in correct index order?
i have core data attribute, contentid
. objects listed as: 5, 4, 3, 2, 1, 0
i query web database pushes updates since highest contentid
, 5
, , returns array updates: 7, 6
if append core data, order go: 5, 4, 3, 2, 1, 0, 7, 6
how prepend front correctly?
and how prepend in correct order when prepend first new object, 7
, , prepend second item, 6, doesn't go: 6, 7, 5, 4, 3, 2, 1, 0
hope makes sense... thanks!
in general, should not concern order in objects written or stored in database. instead, specify sort order in wish receive data when fetch database.
the sort order fetch determined sortdescriptors
property of nsfetchrequest
. each nssortdescriptor
specifies key determine order, , whether results should in ascending order (v. descending).
so when perform fetch, should in case specify:
let sort = nssortdescriptor(key:"contentid", ascending:false) fetchrequest.sortdescriptors = [sort] let fetchedresults = managedobjectcontent.executefetchrequest(fetchrequest, error: &error) as? [nsmanagedobject]
Comments
Post a Comment