<!--
{
  "availability" : [
    "macOS: -"
  ],
  "documentType" : "symbol",
  "framework" : "AppKit",
  "identifier" : "/documentation/AppKit/NSDocumentController/document(for:)-a5yd",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "AppKit"
    ],
    "preciseIdentifier" : "c:objc(cs)NSDocumentController(im)documentForWindow:"
  },
  "title" : "document(for:)"
}
-->

# document(for:)

Returns the document object whose window controller owns a specified window.

```
func document(for window: NSWindow) -> NSDocument?
```

## Parameters

`window`

The window owned by the window controller.

## Return Value

The document object whose window controller owns `window`. Returns `nil` if `window` is `nil`, if `window` has no window controller, or if the window controller does not have an association with an instance of `NSDocument`.

## See Also

[`documentForFileName:`](/documentation/AppKit/NSDocumentController/documentForFileName:)

Returns the document object for the file in which the document data is stored.



---

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)