swift - MacOS Application Class data with segue -
i'm using cocoa , swift 3 develop macos. trying use following code set user defaults key (boolean) true
when user clicks on menu item, on main menu.
class app: nsapplication, nsapplicationdelegate { @iboutlet weak var connec: nsmenuitem! @ibaction func connec(_ sender: any) { //user has clicked menu item userdefaults.standard.set(true, forkey: "calledfrommenu") userdefaults.standard.synchronize() //i know it's deprecated, worth shot though print(userdefaults.standard.value(forkey: "calledfrommenu")) print("menu") //neither of these print when click button, segue happens. //there show segue in interface builder, cannot invoke custom seguewithident here either } }
the app perform segue, none of functions. assume because performs segue first therefore bypassing code, makes sense me. set key true
, have segue out of main menu (file>connection handler
) when menu item clicked. makes sense, in advance.
instead of ibaction, can synchronize menu item boolean value in user defaults dragging user defaults controller scene containing menu bar, , binding "value" binding of menu item user defaults controller, defaults key in "model key path" field. tried this, , seems keep value synced when menu item set perform segue.
Comments
Post a Comment