0
    func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
    let strategyPicker=segue.destination as! StrategyViewController
    strategyPicker.folder=self.folder
    NSLog("Tried to pass \(self.folder) into \(String(describing: strategyPicker.folder))")
}

Trying to debug in lldb, it seems that simply assigning segue.destination is triggering the viewDidAppear in the destination view controller. I am getting a fatal error in viewDidAppear in the destination before passing the folder. I understand that any initializer code has to run (and it does--a couple of fields are correctly initialized according to lldb e commands). It just does not make sense that the viewDidAppear is called before the prepareForSegue finishes.

I have breakpoints on the strategyPicker.folder assignment and the NSLog and neither triggers before the error in the destination viewDidAppear.

Any advice?

1 Answers1

2

viewDidLoad/viewWillAppear/viewDidAppear aren't called before prepare(for:sender:) is called.

The function you have shown isn't being called as it doesn't have the correct method signature. You want

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
    if let strategyPicker=segue.destination as? StrategyViewController {
        strategyPicker.folder=self.folder
        NSLog("Tried to pass \(self.folder) into \(String(describing: strategyPicker.folder))")
    }
}

Also, since you mentioned a crash in your destination view controller, it is likely that you are force-unwrapping folder there; you should probably re-think this and code defensively. Conditionally unwrap and display an appropriate error message if folder is nil.

Paulw11
  • 108,386
  • 14
  • 159
  • 186