As far as I know, this would work in Objective-C:
self.window.rootViewController.class == myViewController
How can I check if the current v
For types you can use is
and if it is your own viewcontroller class then you need to use isKindOfClass
like:
let vcOnTop = self.embeddedNav.viewControllers[self.embeddedNav.viewControllers.count-1]
if vcOnTop.isKindOfClass(VcShowDirections){
return
}
Try this
if self is MyViewController {
}
Swift 3
Not sure about you guys, but I'm having a hard time with this one. I did something like this:
if let window = UIApplication.shared.delegate?.window {
if var viewController = window?.rootViewController {
// handle navigation controllers
if(viewController is UINavigationController){
viewController = (viewController as! UINavigationController).visibleViewController!
}
print(viewController)
}
}
I kept getting the initial view controller of my app. For some reason it wanted to stay the root view controller no matter what. So I just made a global string type variable currentViewController
and set its value myself in each viewDidLoad()
. All I needed was to tell which screen I was on & this works perfectly for me.