How do you check current view controller class in Swift?

前端 未结 15 789
梦谈多话
梦谈多话 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 02:03

    To go off of Thapa's answer, you need to cast to the viewcontroller class before using...

       if let wd = self.view.window {
            var vc = wd.rootViewController!
            if(vc is UINavigationController){
                vc = (vc as! UINavigationController).visibleViewController
            }
            if(vc is customViewController){
                var viewController : customViewController = vc as! customViewController
    

提交回复
热议问题