Re: Automatically restore last saved document on application launch
Re: Automatically restore last saved document on application launch
- Subject: Re: Automatically restore last saved document on application launch
- From: Quincey Morris <email@hidden>
- Date: Thu, 10 Mar 2016 23:14:55 -0800
- Feedback-id: 167118m:167118agrif8a:167118sY61OrIlYq:SMTPCORP
On Mar 10, 2016, at 17:05 , Eric Gorr <email@hidden> wrote:
>
> I have a Core Data Document Based OS X application written in swift and using storyboards. Whenever I build and launch the app, instead of automatically opening the last opened document(s), it will create a new document. What I want to be able to do is have the application automatically restore whatever documents were last opened on application launch, if they are available. How can I do this?
I believe there’s nothing special to ease this case (as opposed to NSDocument-based apps, which have state restoration support provided by NSDocumentController). You’ll have to do this manually:
1. Set a state restoration class on each restorable window. You might use the window controller class, or the app delegate class, depending on what’s convenient.
2. Implement the state restoration protocol in this class. This is basically a way of establishing a link between a restoration ID and a window that may or may not exist at the time this is invoked.
3. Save and restore custom state in a suitable place, either a subclass of NSWindow, or a subclass of NSWindowController: a NSResponder subclass that’s going to be in the responder chain.
The trick to it is to remember that state restoration is a layer on top of normal NSWindow handling, so you’re in charge of (re)creating the windows when the app launches. Window controllers are not intrinsically involved in state restoration, but in most cases (I’d imagine) it’s going to be easiest to centralize the actual work in the window controller.
There’s been another thread about this in the last week or so, where we went into this in a fair amount of detail.
_______________________________________________
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