Monday, October 12, 2015

It is now possible to check the version using available from Swift2.0.
if #Available (iOS 8.0 , *) {
     // IOS8.0 more if only the processing of
}
The syntax is as above, #Abailable (Platform version, ...) will be.
At the end * indicates that "otherwise specified with respect to other platforms." 
In other words, in the example above, iOS other than the platform (WatchOS,OSX will be that it is not specified in particular with respect to, etc.).
In addition, when the processing of post-conditions specified is large, it would be good to use the guard statement because the contents of the if statement would parentheses bad increases.
guard #Available (iOS 8.0 , *)  else {
     Return
}

Processing of // case of iOS8.0 or more only
Conversely, self-made method in order not to be used outside the platform version that you specify and classes available (platform version, ...)should be used.
// IOS7.0 and Yobe not only from later 
Attoavailable (iOS 7.0 , *)
funk doSomething () {
    
}
Thus available With this method when you call the #available will require conditional expression.
if #Available (iOS 7.0 , *) {
    doSomething ()
}
Reference article
www.hackingwithswift.com

No comments:

Post a Comment