Group Group Group Group Group Group Group Group Group

Core Data in a UITabBarController

#1

I am using your Dog Walk tutorial as my starting point for my own project. But my app keeps crashing when I fetch data in the ViewController, Probably because I have a UITabBarController between my UINavigationController and my ViewController. I am not sure if I got this right but In my appDelegate the folowing code sets my ViewController as my rootViewController?

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { 
    guard
        let navController = window?.rootViewController as? UINavigationController,
        let viewController = navController.topViewController as? ViewController else
    {
        return true
    }
    viewController.managedContext = coreDataStack.managedContext
    return true
}

If I remove my UITabBarController it runs fine but I need to have the UITabbar, so I reckon I have to make some changes to the above code? Please lead me in the right direction.

thanks,
Joachim

opened #3
#4

@joachimfh Thanks very much for your question and my apologies for the delay.

My advice to you would be to first implement your TabBarController in your AppDelegate. In your code above, you’re using a standard UIViewController. Once you’re able to run your code and display your UITabBarController, then I would go ahead and incorporate Core Data as part of the project.