swift 的宏定义
来源:互联网 发布:辛普森悖论 知乎 编辑:程序博客网 时间:2024/05/23 02:05
swift中没有了#Define这种宏定义了,可以用let来声明常量来取代,判断当前系统版本
let IS_IOS7 = (UIDevice.currentDevice().systemVersion as NSString).doubleValue >= 7.0 let IS_IOS8 = (UIDevice.currentDevice().systemVersion as NSString).doubleValue >= 8.0
对于复杂表达式的宏,可以用全局的func函数代替,比如上面的两个系统判断,可以修改成下面的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)
0 0
- swift 的宏定义
- swift的‘宏定义’
- 没有宏定义的swift???
- Swift类似宏定义
- swift之宏定义
- Swift 宏定义
- Swift中的宏定义
- Swift 宏定义
- swift 宏定义
- Swift怎么定义宏
- Swift宏定义
- swift 宏定义
- Swift开发之 ---- Swift宏定义
- swift 2.0 类的定义
- swift常量的定义使用
- OC的全局引用和Swift的宏定义
- swift中类似宏定义
- swift 中怎么定义宏
- Algorithms—9.Palindrome Number
- 苹果App Store应用程序的下载链接地址
- jQuery为多元素添加统一样式
- 利用struts的同步令牌机制避免form的重复提交
- hadoop 2.4.1配置ssh免密码登陆
- swift 的宏定义
- Ehcache——监听器
- jQuery获得包含margin的outerWidth和outerHeight
- [LeetCode] HouseRobber
- 黑马程序员——OC—OC中的面向对象
- clear的理解
- background-attachment:fixed实现背景固定的效果
- Subsets II
- Java annotation简介2