nsmanagedobject - Objective C - Core Data record update -
i have update records in core data. right way?
nsmanagedobjectcontext *context = [self managedobjectcontext]; nsmutablearray *poifromcd=(nsmutablearray *)[self takepoifromcoredata]; (int i=0; i<[array count]; i++) { (int j=0; j<[poifromcd count]; j++) { poi *poi=(poi *)[poifromcd objectatindex:j]; if ([[[array objectatindex:j]objectforkey:@"poiid"]isequaltostring:poi.poiid]) { poi *p=[poifromcd objectatindex:j]; p.poiid=[[array objectatindex:i]objectforkey:@"poiid"]; p.lastmod=[[array objectatindex:i]objectforkey:@"lastmod"]; } else { poi *p; p=[nsentitydescription insertnewobjectforentityforname:@"poi" inmanagedobjectcontext:context]; p.poiid=[[array objectatindex:i]objectforkey:@"poiid"]; p.lastmod=[[array objectatindex:i]objectforkey:@"lastmod"]; } } } nserror *error; if (![context save:&error]) { nslog(@"errore durante il salvataggio: %@", [error localizeddescription]); }
i pass array method, , take data in coredata , put in poifromcd.
please, if had wrong, point me right way! :)
no, not standard way update core data objects. trying treat core data sql , won't work.
core data not sql. entities not tables. objects not rows or records. attributes not columns. core data object graph management system may or may not persist object graph , may or may not use sql far behind scenes so. trying think of core data in sql terms cause misunderstand core data , result in grief , wasted time.
i can't quite tell trying without knowing data model looks have step through arrays of objects this.
Comments
Post a Comment