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
  • 10,408
  • 6
  • 64
  • 118
lsdoy
  • 129
  • 11

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
  • 80,564
  • 16
  • 176
  • 197
2

Solution:

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