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
Unfortunately, the new Nsprocessinfo API is not particularly useful at this time because they do not take effect on iOS 7.
As an alternative, you can use the Systemversion property uidevice to check:
switch
UIDevice.currentDevice().systemVersion.compare(
"8.0.0"
, options: NSStringCompareOptions.NumericSearch) {
case
.OrderedSame, .OrderedDescending:
println(
"iOS >= 8.0"
)
case
.OrderedAscending:
println(
"iOS < 8.0"
)
}
Adaptation screen
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")
}
iOS Tips---Swift to determine iOS version and adaptation