开发者

NSPredicate as a macro?

开发者 https://www.devze.com 2023-02-06 08:11 出处:网络
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:

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]]
0

精彩评论

暂无评论...
验证码 换一张
取 消