ios - How to avoid duplicates when adding to core data? -



ios - How to avoid duplicates when adding to core data? -

i trying figure out how avoid duplicate info beingness added? having columns unique rows, , if column not unique disallow whole row added. add together row this...

if([userprofileid isequaltostring: myid]) { user *users = [nsentitydescription insertnewobjectforentityforname:@"user" inmanagedobjectcontext: _managedobjectcontext]; int = 0; for(i = 0; < responsecount; i++) { [users setuserid:userids[i]]; [users setname:names[i]]; [users setdateretrieved:[nsdate date]]; } //todo have avoid duplicate beingness saved in db nserror *error = nil; if(![_managedobjectcontext save:&error]) { //handle error if not save } [self getdbdata];

you can set nspredicate reflects unique content , run fast query see wether content exists:

set result type nsmanagedobjectidresulttype speed things up:

fetchrequest.resulttype = nsmanagedobjectidresulttype;

and count:

nsuinteger count = [self.managedobjectcontext countforfetchrequest:fetchrequest error:&error];

and check:

if (count > 0){ // unique content exists - nil } if (count == 0){ // save unique content }

hope helps.

ios iphone core-data

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

c# - Create a Notification Object (Email or Page) At Run Time -- Dependency Injection or Factory -

Set Up Of Common Name Of SSL Certificate To Protect Plesk Panel -