Swift 宏定义
来源:互联网 发布:11年体测数据 编辑:程序博客网 时间:2024/05/22 16:43
swift中没有了#Define这种宏定义了,可以用两种途径来代替之前的Define处理的情况,分别是
- 可以用let来声明常量,来取代常量宏定义
- 可以用全局func来替代复杂表达式的宏定义
- < let常量定义>判断当前系统版本
let IS_IOS7 = (UIDevice.currentDevice().systemVersion as NSString).doubleValue >= 7.0 let IS_IOS8 = (UIDevice.currentDevice().systemVersion as NSString).doubleValue >= 8.0这种用let替代#define只适用于一般的常量宏,如果是表达式或者其他复杂的宏,let也无能无力
2.<复杂表达式宏定义>使用全局func函数
func IS_IOS7() ->Bool { return (UIDevice.currentDevice().systemVersion as NSString).doubleValue >= 7.0 } func IS_IOS8() -> Bool { return (UIDevice.currentDevice().systemVersion as NSString).doubleValue >= 8.0 }
这样,就可以在三元表达式中使用了:
navBar = UIView(frame: CGRectMake(0, 0, 320, IS_IOS7() ? 64:44))
还有RGBA宏
RGBA(r, g, b, a) [UIColor colorWithRed:(r)/255.0 green:(g)/255.0 blue:(b)/255.0 alpha:(a)]
可以写成这样:
func RGBA (r:CGFloat, g:CGFloat, b:CGFloat, a:CGFloat) { return UIColor (red: r/255.0, green: g/255.0, blue: b/255.0, alpha: a) }
var theColor : UIColor = RGBA (255, 255, 0, 1)
1 0
- Swift类似宏定义
- swift 的宏定义
- swift之宏定义
- Swift 宏定义
- Swift中的宏定义
- swift的‘宏定义’
- Swift 宏定义
- swift 宏定义
- Swift怎么定义宏
- Swift宏定义
- swift 宏定义
- Swift开发之 ---- Swift宏定义
- swift中类似宏定义
- swift 中怎么定义宏
- 没有宏定义的swift???
- swift中常用宏定义
- 如何为Swift进行宏定义
- swift 知识点 定义函数
- Android属性动画ValueAnimator快速上手
- 离线编程国内外发展现状与前景预测
- Node.js and Express
- java-ToStringBuilder介绍
- 反射父类方法
- Swift 宏定义
- java中list和arrayList区别
- 阶梯乘法——阶乘与梯乘
- Spark2.0.0集群搭建部署
- android开发自定义View(三)仿芝麻信用积分
- Flume采集日志进入HDFS以及Hadoop环境搭建
- 分布式缓存架构基础
- git详解
- 5.20