11

I'm using Xcode 11.1 and my deployment target is iOS 10.0

I can't instantiate a view controller like before. Here is the code in

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]?) -> Bool

let storyboard = UIStoryboard(name: "Main", bundle: nil)
let viewController = storyboard.instantiateViewController(identifier: "TabBarController")

I get the error saying:

'instantiateViewController(identifier:creator:)' is only available in iOS 13.0 or newer

How possibly can one instantiate view controllers from storyboard programmatically on Xcode 11.1. Any other way?

Suh Fangmbeng
  • 573
  • 4
  • 16

3 Answers3

40

You need to use

storyboard.instantiateViewController(withIdentifier: "TabBarController")

the new instantiateViewController(identifier: "TabBarController") is only available on iOS 13 and returns ViewController instead of UIViewController as you can see here

enter image description here

Reinier Melian
  • 20,519
  • 3
  • 38
  • 55
6

You should do following:

let viewController = storyboard.instantiateViewController(withIdentifier: "TabBarController")

parameter should be -withIdentifier- not -identifier-

memtarhan
  • 144
  • 1
  • 3
0
//use instantiateViewController(withIdentifier:"") method to resolve notinstantiateViewController(Identifier:"") 


 let objRef : RatindAndReviewVC = self.storyboard?.instantiateViewController(withIdentifier: "RatindAndReviewVC") as! RatindAndReviewVC

       self.navigationController?.pushViewController(objRef, animated: true)
Davender Verma
  • 503
  • 2
  • 12
  • 2
    Please don't post only code as answer, but also provide an explanation what your code does and how it solves the problem of the question. Answers with an explanation are usually more helpful and of better quality, and are more likely to attract upvotes. – Mark Rotteveel Aug 14 '20 at 10:39