Hi all,
I have a document based app where I'm trying to restore an Inspector window when the app restarts.
Window restoration for the documents works well using willEncodeRestorableState and didDecodeRestorableState.
In my Obj-C apps I used this code with success:
+ (void)restoreWindowWithIdentifier:(NSString *)identifier state:(NSCoder *)state completionHandler:(void (^)(NSWindow *, NSError *))completionHandler
{
NSWindow *resultWindow = nil;
if ([identifier isEqualToString:@"Inspector"]) {
/
resultWindow = [[InspectorPanelController sharedInspectorPanelController] window];
} else {
/
resultWindow = nil;
}
/
completionHandler(resultWindow,nil);
}
But now I'm trying to do the same in my new project using Swift and Storyboards... but it just doesn't work. This is what I got this far...
class InspectorWindowController: NSWindowController {
override func windowDidLoad()
{
super.windowDidLoad()
window!.restorationClass = self.dynamicType
}
internal static func restoreWindowWithIdentifier(identifier: String, state: NSCoder, completionHandler: ((NSWindow?,NSError?) -> Void))
{
if identifier == "Inspector" {
let storyboard = NSStoryboard (name: "Main", bundle: nil)
let controller = storyboard.instantiateControllerWithIdentifier ("InspectorWindowController") as! InspectorWindowController
let window = controller.window
completionHandler(window, nil)
}
}
}
The Inspector window is never restored even though the completion handler of restoreWindowWithIdentifier returns a window?
Anyone got this working in Swift using Storyboards?
Best regards / Jörgen