# Passing the context from AppDelegate - Chapter 27 - Saving Locations

**URL:** <https://forums.kodeco.com/t/passing-the-context-from-appdelegate-chapter-27-saving-locations/94084>\
**Category:** iOS Apprentice\
**Created:** [January 9, 2020, 9:43pm UTC](https://forums.kodeco.com/t/passing-the-context-from-appdelegate-chapter-27-saving-locations/94084 "2020-01-09T21:43:00Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![turon](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/turon/32/81494_2.png) [@turon](https://forums.kodeco.com/u/turon)\
**Post date:** [January 9, 2020, 9:43pm UTC](https://forums.kodeco.com/t/passing-the-context-from-appdelegate-chapter-27-saving-locations/94084/1 "2020-01-09T21:43:00Z")

</div>

Hi everyone, i’m having an issue with an `UIWindow` variable. In the Page 642, i need to pass the `NSManagedObject` from the `AppDelegate`. First i declared `window : UIWindow?` as an optional. Then how it says in the book, i declared `let tabController = window!.rootViewController as! UITabBarController`. But in the debug console it shows me an error like this: _Unexpectedly found nil while unwrapping an Optional value_. I don’t understand why window is nil, either what exactly this window variable does. And if i have fisrt to assing any value to this window variable. I’m usign Xcode 11.3.  
Thanks.

---

<div class="post-metadata">

**Author:** ![superkookai](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/superkookai/32/108506_2.png) [@superkookai](https://forums.kodeco.com/u/superkookai)\
**Post date:** [January 10, 2020, 1:36pm UTC](https://forums.kodeco.com/t/passing-the-context-from-appdelegate-chapter-27-saving-locations/94084/2 "2020-01-10T13:36:26Z")

</div>

I have same problem with you. Waiting someone to answer also. I think it is because iOS13 has SceneDelegate working with AppDelegate.

---

<div class="post-metadata">

**Author:** ![turon](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/turon/32/81494_2.png) [@turon](https://forums.kodeco.com/u/turon)\
**Post date:** [January 10, 2020, 1:57pm UTC](https://forums.kodeco.com/t/passing-the-context-from-appdelegate-chapter-27-saving-locations/94084/3 "2020-01-10T13:57:52Z")

</div>

It’s very weird. I tried the book code, here I leave the link for the download: [https://store.raywenderlich.com/products/ios-apprentice-source-code](https://store.raywenderlich.com/products/ios-apprentice-source-code). With that code it works for me correctly (use the final chapter 27) And in the AppDelegate I have the same code as the one in the book.

---

<div class="post-metadata">

**Author:** ![superkookai](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/superkookai/32/108506_2.png) [@superkookai](https://forums.kodeco.com/u/superkookai)\
**Post date:** [January 11, 2020, 4:11am UTC](https://forums.kodeco.com/t/passing-the-context-from-appdelegate-chapter-27-saving-locations/94084/4 "2020-01-11T04:11:13Z")

</div>

I found solution, you just move all code from AppDelegate to SceneDelegate.

---

<div class="post-metadata">

**Author:** ![shogunkaramazov](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/shogunkaramazov/32/108826_2.png) [@shogunkaramazov](https://forums.kodeco.com/u/shogunkaramazov)\
**Post date:** [July 2, 2020, 11:40pm UTC](https://forums.kodeco.com/t/passing-the-context-from-appdelegate-chapter-27-saving-locations/94084/6 "2020-07-02T23:40:35Z")

</div>

Opened on July 2, 2020, 11:40pm UTC



---

<div class="post-metadata">

**Author:** ![shogunkaramazov](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/shogunkaramazov/32/108826_2.png) [@shogunkaramazov](https://forums.kodeco.com/u/shogunkaramazov)\
**Post date:** [July 2, 2020, 11:41pm UTC](https://forums.kodeco.com/t/passing-the-context-from-appdelegate-chapter-27-saving-locations/94084/7 "2020-07-02T23:41:28Z")

</div>

@turon Do you still have issues with this?

---

<div class="post-metadata">

**Author:** ![shogunkaramazov](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/shogunkaramazov/32/108826_2.png) [@shogunkaramazov](https://forums.kodeco.com/u/shogunkaramazov)\
**Post date:** [July 2, 2020, 11:41pm UTC](https://forums.kodeco.com/t/passing-the-context-from-appdelegate-chapter-27-saving-locations/94084/8 "2020-07-02T23:41:50Z")

</div>

@superkookai Glad you sorted it out!
