The class method + (void)restoreWindowWithIdentifier:(NSString *)identifier state:(NSCoder *)state completionHandler:(void (^)(NSWindow *, NSError *))completionHandler
as described by "El Developer" is only half of the solution.
The class that implements the method (and conforms to the NSWindowRegistration protocol) also has to be registered as the window's "Restoration Class".
When the window is initially created, register it using the - (void)setRestorationClass:(Class <NSWindowRestoration>)restorationClass
method.
e.g. for a window controller, for initialization:
_myWindowController = [[MyWindowController alloc] initWithWindowNibName:@"MyWindowController"];
_myWindowController.window.restorationClass = self.class;
_myWindowController.window.identifier = @"MyWindow";
for restoration:
+ (void)restoreWindowWithIdentifier:(NSString *)identifier state:(NSCoder *)state completionHandler:(void (^)(NSWindow *, NSError *))completionHandler {
if ([identifier isEqualToString:@"MyWindow"]) {
MyAppDelegate *appDelegate = (MyAppDelegate *)NSApplication.sharedApplication.delegate;
NSWindow *myWindow = appDelegate.myWindowController.window;
completionHandler(myWindow, nil);
}
}