I do not see a problem with your predicate. Single =
perfect if you want to match exact strings. If you don't need a wildcard, you don't need a slow LIKE. ( Predicate format string syntax )
However, there is a problem in your code, and this can lead to incorrect assumptions. Your if / then / else or at least the first message is incorrect. If you retrieve, it does not return an array, this means that the selection was not completed, this does not mean that the selection did not return objects.
It should be something like this:
if (!matches) { NSLog(@"Error: couldn't execute fetch request %@", error); } else if([matches count] > 1) { NSLog(@"Error: More than one object for unique record"); returnValue = YES; } else if ([matches count] == 0) { NSLog(@"couldn't match objects"); returnValue = NO; } else {
Oh, and I would change the order of the conditions. In my opinion, such a structure as (! Matches), ([matches count] == โโ1), ([count count] == โโ0), (else) makes more sense and is easier to read. You put the most important (because this is what you really want) in the last "anonymous".
source share