2

I'm working on a somewhat new project (with Swift) and I just realized UIApplication.keywindow and UIApplicationDelegate.window are being used (apparently) like they are the same.

From this question I understand the are in fact NOT the same; but it's really not clear to me why or how they are different, when should each one be used.

Also the documentation here and here is rather cryptic in the meaning of each attribute, so I don't really understand if I can use one or the other, if I should one of both. In any case, any light on this mess would be great. Thanks!

Community
  • 1
  • 1
Andres C
  • 463
  • 6
  • 26
  • What are you using the window for? The window object is used infrequently on iOS compared to OSX. – EricS Aug 06 '16 at 00:53
  • Care to explain further what you mean? I use the window to get the root and push a controller. Don't really understand which one should I use, or if I can use either one of them, and why. – Andres C Aug 06 '16 at 19:17
  • Most of our projects have a UINavigationController, so we push controllers via `[self.navigationController pushViewController:vc animated:YES];`. We normally put the root viewController into the app delegate, so there's no need to use the `window` property. Having said that, there are times we use it to present alert-type views. – EricS Aug 07 '16 at 19:17
  • 1
    In any case, I would use `UIApplicationDelegate.window` for what you're doing. – EricS Aug 07 '16 at 19:18
  • Possible duplicate of [diffrence between \[\[\[\[UIApplication sharedApplication\] delegate\] window\] and \[\[UIApplication sharedApplication\].keyWindow?](https://stackoverflow.com/questions/21698482/diffrence-between-uiapplication-sharedapplication-delegate-window-and-u) – mfaani May 30 '18 at 22:14

0 Answers0