ios - Filter in CoreData? -


i wrote method below

-(nsarray*)getclubdetaileddeals:(nsstring *)clubid{      nserror *error;     nsmanagedobjectcontext *context = [self managedobjectcontext];      nsfetchrequest * fetchrequest = [[nsfetchrequest alloc] init];      nsentitydescription *entity = [nsentitydescription entityforname:@"clubdetailsdeals"                                               inmanagedobjectcontext:context];      [fetchrequest setentity:entity];      nsarray *fetchedarray1 = [[context executefetchrequest:fetchrequest error:&error] mutablecopy];      clubdetailsdealsdao *obb = [fetchedarray1 objectatindex:0];      nslog(@"my id %@ , count %d", obb.dealname, [fetchedarray1 count]);         nslog(@"deal %@", clubid);      nspredicate *predicate = [nspredicate predicatewithformat:@"(%k contains %@)", @"clubid", clubid];      //nspredicate *predicate = [nspredicate predicatewithformat:@"dealid contains[cd] %@", dealid];      [fetchrequest setpredicate:predicate];      nsarray *fetchedarray = [[context executefetchrequest:fetchrequest error:&error] mutablecopy];      nslog(@"count of arary ~~~~ %d", [fetchedarray count]);      return fetchedarray; } 

here, count of array in log

* nslog(@"my id %@ , count %d", obb.dealname, [fetchedarray1 count]);*

is showing more 1 elements, more add, increasing properly.

but when fetch using query

nspredicate *predicate = [nspredicate predicatewithformat:@"(%k contains %@)", @"clubid", clubid]; 

its returning nothing, object available in coredata.

so right query fetch match clubid, i.e nsstring?

try this,

-(nsarray*)getclubdetaileddeals:(nsstring *)clubid{      nserror *error;     nsmanagedobjectcontext *context = [self managedobjectcontext];      nsfetchrequest * fetchrequest = [[nsfetchrequest alloc] init];      nsentitydescription *entity = [nsentitydescription entityforname:@"clubdetailsdeals"                                               inmanagedobjectcontext:context];      [fetchrequest setentity:entity];  [fetchrequest setpredicate:[nspredicate predicatewithformat:@"(dealid  contains[cd] %@)", clubid]];      nsarray *fetchedarray = [[context executefetchrequest:fetchrequest error:&error] mutablecopy];      nslog(@"count of arary ~~~~ %d", [fetchedarray count]);      return fetchedarray; } 

Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -