Reputation: 129
#define SDNSPredicate(key,value) \
[NSPredicate predicateWithFormat:@"#key == %@",value];
When I use SDNSPredicate(@"hCName",@"ccc")
, I expect hCName == "ccc"
but it becomes key == "ccc"
How to make it right?
Upvotes: 1
Views: 87
Reputation: 81868
how to make it right?
Use a function. Macros are evil.
static inline NSPredicate *SDNSPredicate(NSString *key, NSString *value) {
return [NSPredicate predicateWithFormat:@"%@ == %@", key, value];
}
Upvotes: 5
Reputation: 957
Solution:
#define SDNSPredicate(key,value) \
[NSPredicate predicateWithFormat:@"%K == %@",key,value];
Upvotes: 2