Default project Xcode 7 with OS X Cocoa app, with Storyboards but without Core 
Data nor Documents. Somewhere I messed up and State Restoration stopped working 
correctly. It somehow thinks when quit happens and any open windows get 
automatically closed that those windows were user-closed instead and therefore 
not restored. I was having problems before with windows hanging around in the 
wrong position, so I must have fried a setting somewhere or made some other bad 
assumption.

//===
    private func createWindow(sender: AnyObject?) -> Bool {
        guard let controller = 
self.mainStoryboard.instantiateControllerWithIdentifier(Names.mainWindowControllerID)
 as? NSWindowController, window = controller.window else {
            return false
        }

        let notificationCenter = NSNotificationCenter.defaultCenter()
        let observer = 
notificationCenter.addObserverForName(NSWindowWillCloseNotification, object: 
window, queue: NSOperationQueue.mainQueue()) { [unowned self] note in
            guard let window = note.object as? NSWindow, controller = 
window.windowController else {
                return
            }
            self.windowControllers.remove(controller)
            if let observer = self.observers.removeValueForKey(controller) {
                notificationCenter.removeObserver(observer)
            }
        }
        self.observers[controller] = observer
        self.windowControllers.insert(controller)
        controller.showWindow(sender)
        return true
    }
//===

The “applicationOpenUntitledFile:” and “newDocument:” methods call this method. 
The “windowControllers” property is a Set<NSWindowController> and “observers” 
is a [NSWindowController: AnyObject]. The set retains the window controllers 
(the system will release them and close their windows otherwise) and the 
dictionary lets me release the observers later. Am I messing something up in 
that code so the window is aborted (instead of fully closing) to death and 
messing up the restore state?

I have modified the window-controller and/or window parts of the main 
storyboard, but I don’t see where anything could have gone wrong there.

— 
Daryle Walker
Mac, Internet, and Video Game Junkie
darylew AT mac DOT com 

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to