Iphone 如何为此使用nspredicate?

Iphone 如何为此使用nspredicate?,iphone,Iphone,我在以下代码中使用nspredicate时遇到困难: for (int i=0; i<[nodes count]; i++) { NSMutableDictionary *dict=[nodes objectAtIndex:i]; NSInteger docid = [[dict objectForKey:@"docid"] integerValue]; NSString *strPred = [NSString stringWithFormat:@"docId

我在以下代码中使用nspredicate时遇到困难:

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];
}

对于(int i=0;i您只需将一个var初始化为零。如果对象计数大于零,您只需更改var值。我可以从您的解释中预测到这一点。如果我在某个地方出错,请告诉我