define用法补充
程序员文章站
2022-03-15 22:27:05
...
define用法补充
#define Method1(name) [[ClassName shareInstall] setName:@#name]
#define Method2(name) [[ClassName shareInstall] setName:name]
interface ClassName : NSObject
- (void)setName:(NSString *)name;
@end
/***************************************************************/
@implementation ClassModule
- (void)test {
// #代表"" => "Nike"
Method1(Nike);
Method2(@"Nike");
}
@end
#define MethodInit(...) self = [super init]; \
if(self) { \
__VA_ARGS__; \
} \
return self; \
@implementation ClassName
{
NSMutableDictionary *_cache;
}
- (id)initWithCapacity:(NSUInteger)capacity {
//代码注入
MethodInit(_cache = [[NSMutableArray alloc] initWithCapacity:capacity]);
}
@end
上一篇: auto与decltype
下一篇: python每日一练