Group Group Group Group Group Group Group Group Group

Chapter 32 - CoreData Unwrapping Optional Error

Hi guys,

Pretty stuck on an unwrapping optional issue while trying to get App Delegate to pass the context along to the CurrentLocationViewController through application(:didFinishLaunchingWIthOptions). I’m running the latest xCode (11.7), and the creation of the CoreData files added more code than your tutorial suggests. Everything looks good and I’ve reviewed your finished sample project for Chapter 32 - but no luck. The Error is:
2020-10-09 13:29:02.546646-0400 MyLocations_2020[5740:1113110] Fatal error: Unexpectedly found nil while unwrapping an Optional value: file … AppDelegate.swift, line 19

The code where the error is found:

func application( _ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any ]?) -> Bool {

--------> let tabController = window!.rootViewController as ! UITabBarController <------------

if let tabViewControllers = tabController.viewControllers {

let navController = tabViewControllers[0] as ! UINavigationController

let controller = navController.viewControllers.first as ! CurrentLocationViewController

controller.managedObjectContext = managedObjectContext




return true


Please help :slight_smile:
Thank you,


This topic was automatically closed after 166 days. New replies are no longer allowed.