I read all Q&A related to Macros in Swift
, And i did figure out that everything in Swift now global,
Am i right?
What I did is to create a class method that returns the #define.
Example:
.h file:
#define COLOR_CODE(red, green, blue, alpha) [UIColor colorWithRed: red/255.0 green: green/255.0 blue: blue/255.0 alpha: alpha]
+ (UIColor*)colorCodeWithRed:(CGFloat)red green:(CGFloat)green blue:(CGFloat)blue alpha:(CGFloat)alpha;
.m file:
+ (UIColor*)colorCodeWithRed:(CGFloat)red green:(CGFloat)green blue:(CGFloat)blue alpha:(CGFloat)alpha { return COLOR_CODE(red, green, blue, alpha); }
And in Swift:
Since this is a class method you can now use it almost as you would the #define. If you change your #define macro - it will be reflected in the new method you created In Swift:
let color = YourClass.colorCodeWithRed(72.0, green: 55.0, blue: 100.0, alpha: 1.0);