1
#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?

Stanislav Pankevich
  • 11,044
  • 8
  • 69
  • 129
lsdoy
  • 129
  • 12

2 Answers2

5

how to make it right?

Use a function. Macros are evil.

static inline NSPredicate *SDNSPredicate(NSString *key, NSString *value) {
    return [NSPredicate predicateWithFormat:@"%@ == %@", key, value];
}
Community
  • 1
  • 1
Nikolai Ruhe
  • 81,520
  • 17
  • 180
  • 200
2

Solution:

#define SDNSPredicate(key,value) \
[NSPredicate predicateWithFormat:@"%K == %@",key,value];
Govind Prajapati
  • 957
  • 7
  • 24