How to grab a reference to the top most UIWindow

It’s easy to get a reference to the very top window if we write code in our AppDelegate. We can easily refer to it with self.window.

But if you’re writing code in another class then this doesn’t work. Instead, we can use UIApplication and ask for the keyed window – that’s the one currently being displayed:

// grab reference to our keyed window
UIWindow *window = [UIApplication sharedApplication].keyWindow;




Leave a Reply