On Mar 10, 2016, at 17:05 , Eric Gorr <mail...@ericgorr.net> 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 (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