运算符可以用于宏函数的替换部分。这个运算符把两个语言符号组合成单个语言符号,为宏扩展提供了一种连接实际变元的手段
例子一:
#import "ViewController.h"
#define LB_Create(magic) \
- (NSString *)magic {\
return [self lb_##magic];\
}\
@interface ViewController ()
@property (nonatomic, copy, readonly) NSString *testStr;
@property (nonatomic, copy, readonly) NSString *lb_testStr;
@end
@implementation ViewController
LB_Create(testStr)
- (void)viewDidLoad {
[super viewDidLoad];
NSLog(@"%@",self.testStr);
}
- (NSString *)lb_testStr {
return @"you are so cool !";
}
@end
编译运行输出:
you are so cool !
网友评论