标签:
operatingSystemVersion
为了更复杂的版本比较,operatingSystemVersion能够被直接检查。将它和Swift模式比较和switch语句组合,可以使得代码更简洁。
let os = NSProcessInfo().operatingSystemVersion
switch
(os.majorVersion, os.minorVersion, os.patchVersion) {
case
(8, _, _):
println(
"iOS >= 8.0.0"
)
case
(7, 0, _):
println(
"iOS >= 7.0.0, < 7.1.0"
)
case
(7, _, _):
println(
"iOS >= 7.1.0, < 8.0.0"
)
default
:
println(
"iOS < 7.0.0"
)
}
UIDevice systemVersion
可惜的是,新NSProcessInfo API目前并不是特别有用,因为它们在iOS 7上不生效。
作为替代,可以使用systemVersion属性UIDevice来进行检查:
switch
UIDevice.currentDevice().systemVersion.compare(
"8.0.0"
, options: NSStringCompareOptions.NumericSearch) {
case
.OrderedSame, .OrderedDescending:
println(
"iOS >= 8.0"
)
case
.OrderedAscending:
println(
"iOS < 8.0"
)
}
适配屏幕
switch UIDevice.currentDevice().systemVersion.compare("7.0.0", options: NSStringCompareOptions.NumericSearch) {
case .OrderedSame, .OrderedDescending:
println("iOS >= 7.0")
self.edgesForExtendedLayout = UIRectEdge.None
self.automaticallyAdjustsScrollViewInsets = false
case .OrderedAscending:
println("iOS < 7.0")
}
标签:
原文地址:http://my.oschina.net/u/2331935/blog/484324