-1

My code does not work in Swift 5

var myTabBar = self.storyboard?.instantiateViewController(withIdentifier: "myTabBar") as! UITabBarController
var app = UIApplication.shared.delegate as! AppDelegate
app.window?.rootViewController = myTabBar

Value of type AppDelegate has no member window

Kamran
  • 14,386
  • 3
  • 30
  • 47
  • https://stackoverflow.com/questions/58188296/how-set-rootviewcontroller-in-scene-delegate-ios-13 reference related to same question – Rubiya Faniband Oct 27 '19 at 06:36

2 Answers2

0

Because in new Xcode window is moved to SceneDelegate

Akshay
  • 56
  • 1
  • 9
  • var myTabBar = self.storyboard?.instantiateViewController(withIdentifier: "myTabBar") as! UITabBarController let app = UIApplication.shared.delegate as? SceneDelegate app?.window?.rootViewController = myTabBar – Akshay Oct 27 '19 at 06:36
0

I'm meeting you more than half-way here, because we really need more details on what's going on and what you're trying to achieve.

But the error is telling you that the AppDelegate doesn't have a variable called window. You probably want the UIApplication object itself, and not its delegate.

Maybe try replacing

var app = UIApplication.shared.delegate as! AppDelegate
app.window?.rootViewController = myTabBar

with

var app = UIApplication.shared
app.keyWindow?.rootViewController = myTabBar
Darren Black
  • 1,020
  • 1
  • 9
  • 28