1

我使用这个宏:

#define fontMacro(name, size) ((UIFont *)[UIFont fontWithName:(NSString *)(name) size:(CGFloat)(size)])

UIFont *font = fontMacro(@"Akrol", 15); // Error: Expected ']'
UIFont *font2 = ((UIFont *)[UIFont fontWithName:(NSString *)(@"Akrol") size:(CGFloat)(15)]); // work fine

那么,我该如何使用fontMacro

4

1 回答 1

2

问题是size您的宏的参数在右侧所有出现fontMacro(@"Akrol", 15)的“大小”处都被扩展,因此扩展为

((UIFont *)[UIFont fontWithName:(NSString *)(@"Akrol") 15:(CGFloat)(15)])
                            unwanted expansion here ---^

将宏参数重命名为_size_或类似名称应该可以解决问题:

#define fontMacro(_name_, _size_) ((UIFont *)[UIFont fontWithName:(NSString *)(_name_) size:(CGFloat)(_size_)])
于 2013-07-29T06:47:26.463 回答