ios - NSFetchedResultsController sorts in wrong order -
i working on project based on coredata example xcode. have entity-class named entity
updated
key stores timestamp entity updated, , nsfetchresultscontroller set sort in descending order:
nsfetchrequest *fetchrequest = [[nsfetchrequest alloc] init]; [fetchrequest setentity:[nsentitydescription entityforname:@"entity" inmanagedobjectcontext:_managedobjectcontext]]; [fetchrequest setfetchbatchsize:20]; [fetchrequest setsortdescriptors:@[[[nssortdescriptor alloc] initwithkey:@"updated" ascending:no]]]; nsfetchedresultscontroller *frc = [[nsfetchedresultscontroller alloc] initwithfetchrequest:fetchrequest managedobjectcontext:_managedobjectcontext sectionnamekeypath:nil cachename:nil];
this works fine on initial load, when insert nsmanagedobject should inserted in between other objects, gets inserted @ top. when relaunch app, gets inserted @ right position.
e.g: table like:
updated: 300 updated: 200 updated: 100
and when insert managedobject: updated: 250
, expect table like:
updated: 300 updated: 250 <-- inserted here updated: 200 updated: 100
but get:
updated: 250 <-- inserted @ top updated: 300 updated: 200 updated: 100
is how nsfetchresultscontroller works, or there way re-sort nsmanagedobjects on every insert? :)
in default, new object inserted top. should keep index of every objects if customize sort. can sort objects in way.
Comments
Post a Comment