Monday, September 9, 2013

CoreData find string - NSPredicate OR for loop?

CoreData find string - NSPredicate OR for loop?

Sorry for my bad English, I'm beginner of using CoreData.
Now I'm trying to find if a NSString does exist in database,
there are two ways to do that, one is using NSPredicate to do request,
if results array count >= 1, means did find something in database
[fetchRequest setPredicate:[NSPredicate predicateWithFormat:@"itemid ==
%@", self.item.itemid]];
NSError *error = nil;
NSArray *results = [context executeFetchRequest:fetchRequest error:&error];
and another is to do loop in array
for (int i=0; i<=[keyArray count]-1 ; i++) {
NSString *keyID = [keyArray objectAtIndex:i];
if ([keyID isEqual:stringToCompare])
return YES;
break;
return NO;
}
I'm using the first method now, but can somebody give me some advice?
which one would be the best? thanks!

No comments:

Post a Comment