views:

88

answers:

1

Hello all, I am currently having an issue pulling all data from db whereby i.e 1 parameter is TRUE.

I am using NSPREDICATE and below is a sample code

NSManagedObjectContext *context = managedObjectContext_;

if (!context) {
    // Handle the error.
    NSLog(@"ERROR CONTEXT IS NIL");
}

NSEntityDescription *entity = [NSEntityDescription entityForName:@"tblcontent" inManagedObjectContext:managedObjectContext_];

NSFetchRequest *request = [[NSFetchRequest alloc] init];

NSPredicate *predicate = [NSPredicate predicateWithFormat:@"bookmarked == YES"];

[request setPredicate:predicate];

I tried setting predicatewithformat to almost everything but it still does not pull out bookmarks which have a YES value.

I even tried ( @"bookmarked == %d",YES) but with not luck. I don't want to have to get the whole array and then filter it manually by doing if(object.bookmarked == YES) .....blabla.

I will really appreciate some help.

Many thanks.

+1  A: 

You haven't mentioned what results you're getting. Two things that are missing from your code listing is where you set your request's entity and where you actually ask the context to execute the fetch request. I'd start there.

Joshua Nozzi
Hi I haven't included that in the code. The results am getting is basically the whole lot. It is as if no filtering is working.
Hi again I think there is something wrong before that. I.e every single content coming back has object.bookmarked = YES even though I have set it to NO by default. I will need to check it out. I reckon , the predicate is working. Thanks anyways.
Hah it is working fine now. stupid me forgot to reset the db from the simulator first doh!! Anyways the code above is fine.