• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
State Restoration thinks all my windows closes prior to quit
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

State Restoration thinks all my windows closes prior to quit


  • Subject: State Restoration thinks all my windows closes prior to quit
  • From: Daryle Walker <email@hidden>
  • Date: Sat, 05 Mar 2016 04:36:34 -0500

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 (email@hidden)

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:

This email sent to email@hidden


  • Follow-Ups:
    • Re: State Restoration thinks all my windows closes prior to quit
      • From: Quincey Morris <email@hidden>
    • Re: State Restoration thinks all my windows closes prior to quit
      • From: Bill Cheeseman <email@hidden>
  • Prev by Date: Re: Starting out with storyboards (on Mac)
  • Next by Date: Re: Starting out with storyboards (on Mac)
  • Previous by thread: Re: Returning a string value from a c function to a Objective-C class method. Is there an approved approach?
  • Next by thread: Re: State Restoration thinks all my windows closes prior to quit
  • Index(es):
    • Date
    • Thread