<!--
{
  "availability" : [
    "macOS: -"
  ],
  "documentType" : "symbol",
  "framework" : "AppKit",
  "identifier" : "/documentation/AppKit/NSWindowController",
  "metadataVersion" : "0.1.0",
  "role" : "Class",
  "symbol" : {
    "kind" : "Class",
    "modules" : [
      "AppKit"
    ],
    "preciseIdentifier" : "c:objc(cs)NSWindowController"
  },
  "title" : "NSWindowController"
}
-->

# NSWindowController

A controller that manages a window, usually a window stored in a nib file.

```
class NSWindowController
```

## Overview

Managing a window entails:

- Loading and displaying the window
- Closing the window when appropriate
- Customizing the window’s title
- Storing the window’s frame (size and location) in the defaults database
- Cascading the window in relation to other document windows of the app

A window controller can manage a window by itself or as a role player in AppKit’s document-based architecture, which also includes [`NSDocument`](/documentation/AppKit/NSDocument) and [`NSDocumentController`](/documentation/AppKit/NSDocumentController) objects. In this architecture, a window controller is created and managed by a “document” (an instance of an `NSDocument` subclass) and, in turn, keeps a reference to the document.

The relationship between a window controller and a nib file is important. Although a window controller can manage a programmatically created window, it usually manages a window in a nib file. The nib file can contain other top-level objects, including other windows, but the window controller’s responsibility is this primary window. The window controller is usually the owner of the nib file, even when it is part of a document-based app. Regardless of who is the file’s owner, the window controller is responsible for freeing all top-level objects in the nib file it loads.

For simple documents—that is, documents with only one nib file containing a window—you need to do little directly with `NSWindowController`; AppKit creates one for you. However, if the default window controller is not sufficient, you can create a custom subclass of `NSWindowController`. For documents with multiple windows or panels, your document must create separate instances of `NSWindowController` (or of custom subclasses of `NSWindowController`), one for each window or panel. An example is a CAD app that has different windows for side, top, and front views of drawn objects. What you do in your [`NSDocument`](/documentation/AppKit/NSDocument) subclass determines whether the default `NSWindowController` or separately created and configured `NSWindowController` objects are used.

### Subclassing NSWindowController

You should create a subclass of `NSWindowController` when you want to augment the default behavior, such as to give the window a custom title or to perform some setup tasks before the window is loaded. In your class’s initialization method, be sure to invoke on `super` either one of the `initWithWindowNibName:...` initializers or the [`init(window:)`](/documentation/AppKit/NSWindowController/init(window:)) initializer. The initializer you choose depends on whether the window object originates in a nib file or is programmatically created.

You can also implement an [`NSWindowController`](/documentation/AppKit/NSWindowController) subclass to avoid requiring client code to get the corresponding nib’s filename and pass it to [`init(windowNibName:)`](/documentation/AppKit/NSWindowController/init(windowNibName:)) or [`init(windowNibName:owner:)`](/documentation/AppKit/NSWindowController/init(windowNibName:owner:)) when instantiating the window controller. The best way to do this is to override [`windowNibName`](/documentation/AppKit/NSWindowController/windowNibName) to return the nib’s filename and instantiate the window controller by passing `nil` to [`init(window:)`](/documentation/AppKit/NSWindowController/init(window:)). Using the [`init(window:)`](/documentation/AppKit/NSWindowController/init(window:)) designated initializer simplifies compliance with Swift initializer requirements.

Typically, you override one of the methods listed below.

|Method Name                                                                                            |Description                                                    |
|-------------------------------------------------------------------------------------------------------|---------------------------------------------------------------|
|``doc://com.apple.appkit/documentation/AppKit/NSWindowController/windowWillLoad()``                    |Override to perform tasks before the window nib file is loaded.|
|``doc://com.apple.appkit/documentation/AppKit/NSWindowController/windowDidLoad()``                     |Override to perform tasks after the window nib file is loaded. |
|``doc://com.apple.appkit/documentation/AppKit/NSWindowController/windowTitle(forDocumentDisplayName:)``|Override to customize the window title.                        |

You can also override [`loadWindow()`](/documentation/AppKit/NSWindowController/loadWindow()) to get different nib-searching or nib-loading behavior, although there is usually no need to do this.

## Topics

### Initializing Window Controllers

[`-  initWithWindow:`](/documentation/AppKit/NSWindowController/init(window:))

Returns a window controller initialized with a given window.

[`-  initWithWindowNibName:`](/documentation/AppKit/NSWindowController/init(windowNibName:))

Returns a window controller initialized with a nib file.

[`-  initWithWindowNibName:owner:`](/documentation/AppKit/NSWindowController/init(windowNibName:owner:))

Returns a window controller initialized with a nib file and a specified owner for that nib file.

[`-  initWithWindowNibPath:owner:`](/documentation/AppKit/NSWindowController/init(windowNibPath:owner:))

Returns a window controller initialized with a nib file at an absolute path and a specified owner.

### Loading and Displaying the Window

[`-  loadWindow`](/documentation/AppKit/NSWindowController/loadWindow())

Loads the receiver’s window from the nib file.

[`-  showWindow:`](/documentation/AppKit/NSWindowController/showWindow(_:))

Displays the window associated with the receiver.

[`windowLoaded`](/documentation/AppKit/NSWindowController/isWindowLoaded)

A Boolean value that indicates whether the nib file containing the receiver’s window has been loaded.

[`window`](/documentation/AppKit/NSWindowController/window)

The window owned by the receiver.

[`-  windowDidLoad`](/documentation/AppKit/NSWindowController/windowDidLoad())

Sent after the window owned by the receiver has been loaded.

[`-  windowWillLoad`](/documentation/AppKit/NSWindowController/windowWillLoad())

Sent before the window owned by the receiver is loaded.

### Accessing the Document

[`document`](/documentation/AppKit/NSWindowController/document)

The document associated with the window controller.

[`-  setDocumentEdited:`](/documentation/AppKit/NSWindowController/setDocumentEdited(_:))

Sets the document edited flag for the window controller.

### Closing the Window

[`-  close`](/documentation/AppKit/NSWindowController/close())

Closes the window if it was loaded.

[`shouldCloseDocument`](/documentation/AppKit/NSWindowController/shouldCloseDocument)

A Boolean value that indicates whether the receiver necessarily closes the associated document when the window it manages is closed.

### Getting Nib and Storyboard Information

[`owner`](/documentation/AppKit/NSWindowController/owner)

The owner of the nib file containing the window managed by the receiver.

[`storyboard`](/documentation/AppKit/NSWindowController/storyboard)

The storyboard file from which the window controller was loaded.

[`windowNibName`](/documentation/AppKit/NSWindowController/windowNibName)

The name of the nib file that stores the window associated with the receiver.

[`windowNibPath`](/documentation/AppKit/NSWindowController/windowNibPath)

The full path of the nib file that stores the window associated with the receiver.

### Accessing Window Attributes and Content

[`shouldCascadeWindows`](/documentation/AppKit/NSWindowController/shouldCascadeWindows)

A Boolean value that indicates whether the window will cascade in relation to other document windows when it is displayed.

[`windowFrameAutosaveName`](/documentation/AppKit/NSWindowController/windowFrameAutosaveName)

The name under which the frame rectangle of the window owned by the receiver is stored in the defaults database.

[`-  synchronizeWindowTitleWithDocumentName`](/documentation/AppKit/NSWindowController/synchronizeWindowTitleWithDocumentName())

Synchronizes the displayed window title and the represented filename with the information in the associated document.

[`-  windowTitleForDocumentDisplayName:`](/documentation/AppKit/NSWindowController/windowTitle(forDocumentDisplayName:))

Returns the window title to be used for a given document display name.

[`contentViewController`](/documentation/AppKit/NSWindowController/contentViewController)

The view controller for the window’s content view.

[`-  dismissController:`](/documentation/AppKit/NSWindowController/dismissController(_:))

Dismisses the window controller.

### Window Property Wrappers

[`WindowLoading`](/documentation/AppKit/NSWindowController/WindowLoading)

A property wrapper that loads the receiver’s window.

### Initializers

[`-  initWithCoder:`](/documentation/AppKit/NSWindowController/init(coder:))

### Instance Properties

[`previewRepresentableActivityItems`](/documentation/AppKit/NSWindowController/previewRepresentableActivityItems)

## Relationships

### Conforms To

[`CustomDebugStringConvertible`](/documentation/Swift/CustomDebugStringConvertible)

[`CustomStringConvertible`](/documentation/Swift/CustomStringConvertible)

[`Equatable`](/documentation/Swift/Equatable)

[`NSObjectProtocol`](/documentation/ObjectiveC/NSObjectProtocol)

[`NSTouchBarProvider`](/documentation/AppKit/NSTouchBarProvider)

[`SendableMetatype`](/documentation/Swift/SendableMetatype)

[`NSCoding`](/documentation/Foundation/NSCoding)

[`Sendable`](/documentation/Swift/Sendable)

[`NSUserActivityRestoring`](/documentation/AppKit/NSUserActivityRestoring)

[`Hashable`](/documentation/Swift/Hashable)

[`NSStandardKeyBindingResponding`](/documentation/AppKit/NSStandardKeyBindingResponding)

[`NSSeguePerforming`](/documentation/AppKit/NSSeguePerforming)

[`CVarArg`](/documentation/Swift/CVarArg)

### Inherits From

[`NSResponder`](/documentation/AppKit/NSResponder)

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)