You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Or they can be converted from a string representation:
letversion=tryVersion("1.2.3-alpha.1+B001")letversion:Version="1.2.3-alpha.1+B001"
// The line above is equivalent to:
letversion=try!Version("1.2.3-alpha.1+B001")
Versions can be compared between each other:
letversion=Version(from:ProcessInfo.processInfo.operatingSystemVersion)if version >"8.0.0"{
// do something in a more amazing way
}elseif version >"7.0.0"
// do it an old-fashioned, legacy-style
}else{
// do not care …
}
Besides UIKit's UIDevice the more preferable variant to access
the operation system version in Foundation as shown below is supported, too.
letversion=Version(from:ProcessInfo.processInfo.operatingSystemVersion)if version =="8.0.1"{NSLog("Sorry no cellular data for you, my friend!")}
Finally Versions can be directly read from bundles:
ifNSBundle(path:"Alamofire.framework").version! <"1.0.0"{println("Howdy Ho! Such an early-adopter using an unstable version!")println("Beware: “Anything may change at any time.”")
// … or insert an actual meaningful special handling
// for version-specific *implementation details* here.
}
ATTENTION: Take care when you check versions of frameworks.
Such checks happen at runtime. They can hurt performance if used at the wrong
place. If there are API changes and you want to consume new methods, you have
to do that at compile time by checking with precompiler macros (#if)
for definitions, which have been passed to the compiler build setting
OTHER_SWIFT_FLAGS.