Instance Method


Invoked to request that a window be restored.


func restoreWindow(withIdentifier identifier: NSUserInterfaceItemIdentifier, state: NSCoder, completionHandler: @escaping (NSWindow?, Error?) -> Void) -> Bool



The unique interface item identifier string that was previously associated with the window. Use this string to determine which window to create.


A coder object containing the window state information. This coder object contains the combined restorable state of the window, which can include the state of the window, its delegate, window controller, and document object. You can use this state to determine which window to create.


A Block object to execute with the results of creating the window. You must execute this block at some point but may do so after the method returns if needed. This block takes the following parameters:

  • The window that was created or nil if the window could not be created.

  • An error object if the window was not recognized or could not be created for whatever reason; otherwise, specify nil. In OS X v10.7, the error parameter is ignored.

Return Value

true if the window was restored; otherwise false.


If the receiver knows how to restore the identified window, it should invoke the completion handler with the window, possibly creating it. It is acceptable to use a pre-existing window, though you should not pass the same window to more than one completion handler. If the receiver cannot restore the identified window (for example, the window referenced a document that has been deleted), it should invoke the completion handler with a nil window.

The receiver is app is passed the identifier of the window, which allows it to quickly check for known windows. For example, you might give your preferences window an identifier of "preferences" in the nib, and then check for that identifier in your implementation. The receiver is also passed the NSCoder instance containing the combined restorable state of the window, its delegate, the window controller, and any document. The receiver may decode information previously stored in the coder to determine what window to restore.

See Also

Restoring App Windows at Launch

func extendStateRestoration()

Allows an app to extend its state restoration period.

func completeStateRestoration()

Completes the extended state restoration.