define用法補充

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

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章