Skip to content

Instantly share code, notes, and snippets.

@pr8x
Created May 9, 2014 15:56
Show Gist options
  • Save pr8x/66b6a52bf77f1f9126bd to your computer and use it in GitHub Desktop.
Save pr8x/66b6a52bf77f1f9126bd to your computer and use it in GitHub Desktop.
NSObject+Predicate
#import <Foundation/Foundation.h>
@interface NSObject (Predicate)
/* applies predicate on single object and returns result */
-(BOOL)meetsPredicate:(NSPredicate*)predicate;
@end
#import "NSObject+Predicate.h"
@implementation NSObject (Predicate)
-(BOOL)meetsPredicate:(NSPredicate *)predicate {
NSArray* single = @[self];
return [[single filteredArrayUsingPredicate:predicate] count] > 0;
}
@end
@pr8x
Copy link
Author

pr8x commented May 9, 2014

Useful when it comes to evaluating objects and check if they meet certain conditions.
Cheers

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment