制作一个宏:如何正确嵌入字符串

lsd*_*doy 1 macros objective-c

#define SDNSPredicate(key,value) \
    [NSPredicate predicateWithFormat:@"#key == %@",value];
Run Code Online (Sandbox Code Playgroud)

当我使用时SDNSPredicate(@"hCName",@"ccc"),我期待hCName == "ccc"但它变成了key == "ccc"

怎么做对了?

Nik*_*uhe 5

怎么做对吗?

使用功能.宏是邪恶的.

static inline NSPredicate *SDNSPredicate(NSString *key, NSString *value) {
    return [NSPredicate predicateWithFormat:@"%@ == %@", key, value];
}
Run Code Online (Sandbox Code Playgroud)