0
我堅持使用nspredicate下面的代碼:這個如何使用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];
}
我有太多,因爲除去ifelse塊,如果計數達到4000循環也適用於那些多次迭代引起的問題,所以序爲了減少這種風險,我想使用NSPredicate。