1

I'm trying to get the blue screen view of my storyboard, but I'm entirely new to this. I don't understand how to navigate through the classes to get to "the blue screen," and it gives me errors.

Story Board Image

The original idea is to propagate the variable "managedObjectContext"(CoreData) through this function in the SceneDelegate.

The error I get is: Initializer for conditional binding must have Optional type, not '[UIViewController]'

This is my SceneDelegate Error

    func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
    // Use this method to optionally configure and attach the UIWindow `window` to the provided UIWindowScene `scene`.
    // If using a storyboard, the `window` property will automatically be initialized and attached to the scene.
    // This delegate does not imply the connecting scene or session are new (see `application:configurationForConnectingSceneSession` instead).
    //guard let _ = (scene as? UIWindowScene) else { return }
    
    let mainViewController = window!.rootViewController as! UINavigationController
    
    if let navViewControllers = mainViewController.viewControllers { //error Initializer for conditional binding must have Optional type, not '[UIViewController]'
        let  controller = navViewControllers.first as! EditViewController
        controller.managedObjectContext = managedObjectContext
    }
    
    
    listenForFatalCoreDataNotifications()
    
    return
}
Omairys
  • 69
  • 1
  • 6

1 Answers1

0

I have decided to propagate the object "managedObjectContext" through the segue. In this case, it has worked better for me because I did not understand very well how to navigate through the storyboard in the scene app

    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
    switch segue.identifier! {
    case addSegueIdentifier:
        guard let navController = segue.destination as? UINavigationController,
        let saveVC = navController.topViewController as? EditViewController else {
            return
        }
        saveVC.managedObjectContext = managedObjectContext
    default:
            break
        }
}
Omairys
  • 69
  • 1
  • 6