欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

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

 

相关标签: define

上一篇: auto与decltype

下一篇: python每日一练