I can\'t seem to get the top most UIViewController without access to a UINavigationController. Here is what I have so far:
UIApplic
Too many flavours but none an iterative elaborated one. Combined from the previous ones:
func topMostController() -> UIViewController? {
var from = UIApplication.shared.keyWindow?.rootViewController
while (from != nil) {
if let to = (from as? UITabBarController)?.selectedViewController {
from = to
} else if let to = (from as? UINavigationController)?.visibleViewController {
from = to
} else if let to = from?.presentedViewController {
from = to
} else {
break
}
}
return from
}