How do you check current view controller class in Swift?

前端 未结 15 753
梦谈多话
梦谈多话 2020-12-13 01:50

As far as I know, this would work in Objective-C:

self.window.rootViewController.class == myViewController

How can I check if the current v

15条回答
  •  囚心锁ツ
    2020-12-13 01:52

    I had to find the current viewController in AppDelegate. I used this

    //at top of class
    var window:UIWindow?
    
    // inside my method/function
    if let viewControllers = window?.rootViewController?.childViewControllers {
        for viewController in viewControllers {
            if viewController.isKindOfClass(MyViewControllerClass) {
                println("Found it!!!")
                }
            }
        }
    

提交回复
热议问题