In my OS X single-window application (not document-based), written using
storyboards in Swift 2, I implement the NSWindowRestoration protocol's static
function restoreWindowWithIdentifier(_:state:completionHandler). I have reached
the point where it is called when it is supposed to be called.
But now what do I do? I can't find any examples showing how to implement the
body of this function in Swift.
At first, when I tried to translate Objective-C examples into Swift, any
reference to the main window controller's 'window' property resulted in the
compile-time error "Instance member 'window' cannot be used on type
'MainWindowController'". Now I realize that I have to create an instance of the
restoration class first. So, this compiles and runs when I use
MainWindowController as the restoration class:
static func restoreWindowWithIdentifier(identifier: String, state: NSCoder,
completionHandler: (NSWindow?, NSError?) -> Void) {
let controller = MainWindowController()
var restoreWindow: NSWindow? = nil
if identifier == "MainWindow" {
restoreWindow = controller.window
}
completionHandler(restoreWindow, nil);
}
However, how do I fit this into the storyboard context? When I create an
instance of MainWindowController here, I seem to be bypassing the segues in the
storyboard. It occurs to me that maybe I should make AppDelegate the
restoration class, instead of MainWindowController. The documentation is
cryptic, even in the NSWindowRestoration.h header file comments. I'm thinking
that then I could just restore the previously encoded underlying data model
values and let the storyboard run by itself as usual. But it isn't clear to me
what will become of the temporary window controller. Or, in other words, how do
I find or create a valid window in this method, as the header file comments say
I should?
I'm having difficulty finding my way. All guidance appreciated.
--
Bill Cheeseman - [email protected]
_______________________________________________
Cocoa-dev mailing list ([email protected])
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 [email protected]