David David - 11 months ago 96
Swift Question

Xcode; Perform segue programmatically, for iOS 7

I'm developing an iOS app with Xcode and Swift.

I'm actually using this code for switching to another ViewController:

let vc : AnyObject! = self.storyboard!.instantiateViewControllerWithIdentifier("FirstView")
if #available(iOS 8.0, *) {
self.showViewController(vc as! UIViewController, sender: vc)
} else {
// Fallback on earlier versions

This is only for iOS 8 and newer. But my app should support iOS 7, too.

Does anybody know what to do in order to support iOS 7?

Answer Source

You can actually use presentViewController, just change StoryboardID of ViewController and call this function

dispatch_async(dispatch_get_main_queue()) {
   let VC1 = self.storyboard!.instantiateViewControllerWithIdentifier("StoryboardID")
   let navController = UINavigationController(rootViewController: VC1) // Creating a navigation controller with VC1 at the root of the navigation stack.
   self.presentViewController(navController, animated:true, completion: nil)