>> BOOL itemIsPresentWithIdenticalValue = [[[self.geofenceObjects allValues] 
>> filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"smi == %@", 
>> thingWeAreCheckingFor]] count] > 0;
...
> I'm not a fan of mashing everything together into one line as it makes 
> readability and comprehension an issue, but this is exactly what I was 
> looking for.

I agree on that point. Another thing I hate: jamming property names into string 
literals for -valueForKey: or predicate formats. It's an easy thing to miss 
during a refactor, and you subvert nice Xcode features like the "Callers" 
listing.

Why not use something like:

        NSSet* matches = [geofenceMap keysOfEntriesPassingTest:^BOOL(id key, id 
obj, BOOL *stop) {
                return [[(MyObjectType*)obj smi] isEqual:findSmi];
        }];
        BOOL isItemPresent = ([matches count] > 0);

That has the benefit of type safety, to make sure the value responds to your 
property getter.

Also, using -keysOfEntriesPassingTest: is going to be more efficient, since 
calling -allValues is going to create a new array just for iteration. I'm 
assuming efficiency doesn't matter here, since otherwise your dictionary would 
be keyed on the "smi" property, but it's a side benefit. If you were concerned 
about efficiency in this case you could set the test block's stop parameter to 
YES once you'd found the first match.

~Martin Wierschin


_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to