i am stuck with using nspredicate in the following code:
for (int i=0; i<[nodes count]; i++)
{
NSMutableDictionary *dict=[nodes objectAtIndex:i];
NSInteger docid = [[dict objectForKey:@"docid"] integerValue];
NSString *strPred = [NSString stringWithFormat:@"docId == %i",docid];
[request setPredicate:[NSPredicate predicateWithFormat:strPred]];
NSArray* objects=[[context executeFetchRequest:request error:nil] retain];
NSPredicate *objCount = [NSPredicate predicateWithFormat:[objects count]];
if([objects count])//how do i reduce these if else block too using nsprdicate
{
[dict setObject:@"1" forKey:@"isbookthere"];
}
else
{
[dict setObject:@"0" forKey:@"isbookthere"];
}
[objects release];
[nodes replaceObjectAtIndex:i withObject:dict];
}
i have to remove the ifelse block too since, if the count goes to 4000 the the loop goes for those many iterations which cause problem,so inorder to reduce this risk i am suppose to use NSPredicate.
you simply can have a var initialized with zero.. if object count is greater than zero u simply change the var value. I could predict this much from your explanation. Let me know if i am wrong somewhere.