I have an existing iOS application which is supports from iOS 8. i want to add new features only for iOS 9.
I have created a new storyboard for iOS 9 which is using the iOS 9 features like UIStackView. Appropriate storyboard file is instantiated based on the Device OS version.
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
let storyboard: UIStoryboard
if #available(iOS 9, *, *) {
storyboard = UIStoryboard(name: "Main", bundle: nil)
} else {
storyboard = UIStoryboard(name: "MainOld", bundle: nil)
}
let mainViewController = storyboard.instantiateInitialViewController()
window?.rootViewController = mainViewController
window?.makeKeyAndVisible()
return true
}
But i am getting compilation error on Main.storyboard "UIStackView before iOS 9.0"
I am using Xcode 7 beta 5.
How to use the iOS 9 related features on the iOS 8 supported projects using Swift 2 #availability check
I have got an answer from Quincey Morris on the Apple Cocoa developer email list.
By Default Build for setting in the File Inspector for storyboard file is "deployment Target", which is iOS 8, so compiler throws error.
If i change the "Build for" setting to iOS 9 on the storyboard which uses the iOS 9 features. NO Error, Application runs in both iOS 8 and iOS 9.
You cannot use such #availability
feature in StoryBoard. If you would like to support iOS 8 with UIStackView
, you should construct UIStackView
from code, or use third party's compatible libraries. Like OAStackView or TZStackView.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With