NSWindowController Autosave using Storyboard

前端 未结 3 1392
一整个雨季
一整个雨季 2021-02-13 05:08

I have a Swift application that is launching a simple NSWindow, like so:

func applicationDidFinishLaunching(notification: NSNotification!) {
    let         


        
3条回答
  •  执念已碎
    2021-02-13 05:39

    In order to satisfy the two conditions identified in the accepted answer and comments, subclassing the window controller seems to work. You can then avoid setting this property uniquely in code for every window controller and simply specify the storyboard's window autosave property (and set the window controller's subclass).

    The WindowController's windowFrameAutosaveName must be

    1. not blank
    2. different to Window's frameAutosaveName
    class AutoFrameSavingWindowController: NSWindowController
    {
        override func awakeFromNib() {
            if let autosaveName = window?.frameAutosaveName {
                windowFrameAutosaveName = autosaveName + " temp"
                }
            }
        }
    }
    

提交回复
热议问题