我创建了一个宏来定义一个字符串属性
#define STRING_PREF(NAME) \
@property (nonatomic, strong, getter=NAME, setter=set_##NAME##:) NSString * NAME;
我尝试这样使用它:
STRING_PREF(username)
但最终出现以下错误:
error: pasting formed 'set_username:', an invalid preprocessing token
STRING_PREF(username)
^
foo.h:16:62: note: expanded from macro 'STRING_PREF'
@property (nonatomic, strong, getter=NAME, setter=set_##NAME##:) NSString * NAME;
^
1 error generated.
预处理器不能生成选择器名称吗?