I was looking for a way to find the current top view presented (including Modal Views) and on Stackoverflow some said this was the code to do so:
UIView *topView = [[[[UIApplication sharedApplication] keyWindow] subviews] lastObject];
But I then want to compare that topView to a certain view controller I am in (let's say FirstViewController), to know if the currently presented View Controller is this particular VC. How can I compare a ViewController to this topView? There are so many different answers on the internet about which code to use and I don't find any that gives me a good solution. Basically, let's say I am in FirstViewController.m, I only want to present an alert if the current top view is FirstViewController.m (it works through NSNotification, so right now is also presents an alert from FirstViewController, even when I'm on another ViewController).
What is the right code to use?
Thank you
I found an acceptable answer finally:
This works perfectly. Just one important thing: DON'T USE IT IN viewDidLoad. The view.window will be nil in viewDidLoad, because it won't be added to the application window yet.