macOS how to get data back from popover

I'm so close here... I think I need to set my root VC as the delegate to the popover but I don't know how or even WHERE to do that. Storyboard: separate view controller, modal segue is dragged from menu item to VC. Popover works. I can get data from my textField, print it from popover's VC. Using a protocol / delegate method to get data back. Here is the code:

PopOver VC: //which is a delegate to it's textField as well.

Code Block
protocol ReturnFromPopover
{
  func setStartTC(timecode: Timecode) // Timecode here is a special class I'm using
}
class EnterStartTCPopoverVC: NSViewController, NSTextFieldDelegate {
var returnProtocol: ReturnFromPopover?
func controlTextDidEndEditing(_ notification: Notification) {
     
    printTC(timecode: tempTC) // this works
    returnProtocol?.setStartTC(timecode: tempTC)
    dismiss(self)
  }
}


Root VC:

Code Block
class ViewController: NSViewController, NSPopoverDelegate, ReturnFromPopover {
//instantiate a var called startTC
func setStartTC(timecode: Timecode) {
    startTC = timecode
    print("it worked: \(startTC as Any)")
     
  }
}


it doesn't crash... but it's not bringing the data back thru the function. Any ideas? Thanks so much for your help.

OK, after bashing my head against this for 24 solid hours, I have figured it out. The whole protocol / delegate relationship between the main VC and the popover is pretty confusing. The best explanation handy to me was from Matt Neuburg's book Programming Fundamentals with Swift. Here is how I configured my main VC and my popover. Because my popover instantiates from a menuItem, which isn't part of the application scene (?), I cannot drag an IBAction into my VC code. I create an @IBAction in code in my main VC, and then control drag from the menuItem to the first responder cube above the menu bar in the storyboard, then choose the created IBAction from the massive list. Miraculously, that works. SO...

POPOVER CODE:

Code Block
protocol ReturnFromPopoverDelegate: class
{
  func setStartTC(timecode: Timecode)
}
class EnterStartTCPopoverVC: NSViewController
{
weak var delegate: ReturnFromPopoverDelegate?
func controlTextDidEndEditing(_ notification: Notification) {
     
    self.delegate?.setStartTC(timecode: tempTC)
    dismiss(self)
  }
}


MAIN VC CODE:

Code Block
class ViewController: NSViewController, ReturnFromPopoverDelegate
{
@IBAction func enterStartTCMenuItemSelected(_ sender: NSMenuItem) {
    let storyboard = NSStoryboard(name: "Main", bundle: nil)
    let viewController = storyboard.instantiateController(withIdentifier: "EnterStartTCPopoverVC") as! EnterStartTCPopoverVC
    viewController.delegate = self
    presentAsModalWindow(viewController)
     
  }
var startTC: Timecode()
   
  func setStartTC(timecode: Timecode) {
    startTC = timecode
    printTC(timecode: tempTC) //printTC is a special func of my Timecode class
     
  }
}


Completely mind boggling... I hope this helps you return some data from your alt viewController. Keep at it. :}


macOS how to get data back from popover
 
 
Q