ios - How to delete the CoreData Objects with user-defined id? -
i have object this
@interface clubs : nsmanagedobject @property (nonatomic, retain) nsstring * catname; @property (nonatomic, retain) nsstring * clubdescription; @property (nonatomic, retain) nsstring * clubid; @property (nonatomic, retain) nsstring * clubname; @property (nonatomic, retain) nsstring * distance; @property (nonatomic, retain) nsstring * logopath; @property (nonatomic, retain) nsstring * phone; @property (nonatomic, retain) nsstring * clubtype; @end
i want delete object have particular clubid?
suppose there twenty clubs added coredata, these object want delete clubid 120.
thanks
-(void)deleteclubsentity:(nsstring*)clubid // pass value 120 { nserror *error = nil; nsmanagedobjectcontext *context = [self managedobjectcontext]; nsfetchrequest * fetch = [[nsfetchrequest alloc] init]; [fetch setentity:[nsentitydescription entityforname:@"clubs" inmanagedobjectcontext: context]]; [fetch setpredicate:[nspredicate predicatewithformat:@"(clubid contains[cd] %@)",clubid]]; nsarray * records = [context executefetchrequest:fetch error:&error]; (nsmanagedobject * record in records) { [context deleteobject:record]; } [context save:&error]; }
Comments
Post a Comment