#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?
#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?
how to make it right?
Use a function. Macros are evil.
static inline NSPredicate *SDNSPredicate(NSString *key, NSString *value) {
return [NSPredicate predicateWithFormat:@"%@ == %@", key, value];
}
Solution:
#define SDNSPredicate(key,value) \
[NSPredicate predicateWithFormat:@"%K == %@",key,value];