NSPredicate as a macro?
I will be adding a series of NSPre开发者_StackOverflow中文版dicates
to my model objects, I would like to add these NSPredicates
to my header as macros, so I could use them like this:
NSArray *filteredResults = FILTER_ARRAY_BY_NAME(rawArray, nameString);
One of the reasons to wanting to do this is to have the different macros visible in my header and make it easy to change/add or delete predicate macros.
Macro syntax still elude me a bit, but how would this NSPredicate translate to a macro?
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"parentCategoryID == '%@'", categoryID];
return [categories filteredArrayUsingPredicate:predicate];
Hope someone can help me out a bit, thanks in advance.
Simple:
#define FILTER_ARRAY_BY_NAME(rawArray, nameString) [rawArray filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"nameString == '%@'", nameString]]
精彩评论