iphone - How to stock NSString in Core Data? -


i have model follows this:

model

then want stock city uitableview. problem is, want hold them in iphone (database) until reach 10, after erases first , adds last. have idea, can't reach add , i'm confused.

enter image description here

when click city, pushes next view sending response json id , name of city.. thats ok. want store in order make same call uitableview (under it) it's "last cities searched" lik that.

i want save id,name , after load in other tableview showing name. i'm ok, can't reach make stock happend.

code:

-(void)tableview:(uitableview *)tableview didselectrowatindexpath:(nsindexpath *)indexpath {  detailtaxi *detailview = [[detailtaxi alloc] initwithnibname:nil bundle:[nsbundle mainbundle]];   nsstring *nomville = [[_jsondict objectatindex:indexpath.row] objectforkey:@"label"]; nsstring *idville = [[_jsondict objectatindex:indexpath.row] objectforkey:@"id"];  detailview.title = nomville; detailview.idville = idville;  nslog(@"valor: %@", nomville); nslog(@"valor: %@", idville);   appdelegate *appdelegate = [[uiapplication sharedapplication] delegate]; nsmanagedobjectcontext *context = [appdelegate managedobjectcontext];  nsstring *insert = [[nsstring alloc] initwithformat:@"%@,%@",idville,nomville]; nsmanagedobject *newville;   nsarray *insertvilles = [insert componentsseparatedbystring:@","];  for(nsstring *insert in insertvilles) {     newville = [nsentitydescription insertnewobjectforentityforname:@"ville" inmanagedobjectcontext:context];      [newville setvalue:[insertvilles objectatindex:0] forkey:@"id"];     [newville setvalue:[insertvilles objectatindex:1] forkey:@"nom"]; }   [self.navigationcontroller pushviewcontroller:detailview animated:yes];  } 

just add new attribute of type nsdate set current date upon creating new entry. once retrieve cities again, use sort descriptor sort cities time saved , use fetch limit.

if deleting previous cities necessary, date attribute prove useful well.


Comments

Popular posts from this blog

django - How can I change user group without delete record -

java - Need to add SOAP security token -

java - EclipseLink JPA Object is not a known entity type -