---
title: "document(for:)"
framework: appkit
role: symbol
role_heading: Instance Method
path: "appkit/nsdocumentcontroller/document(for:)-a5yd"
---

# document(for:)

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

## Declaration

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

## Parameters

- `window`: The window owned by the window controller.

## Return Value

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

### Managing Documents

- [documents](appkit/nsdocumentcontroller/documents.md)
- [addDocument(_:)](appkit/nsdocumentcontroller/adddocument(_:).md)
- [currentDocument](appkit/nsdocumentcontroller/currentdocument.md)
- [hasEditedDocuments](appkit/nsdocumentcontroller/hasediteddocuments.md)
- [removeDocument(_:)](appkit/nsdocumentcontroller/removedocument(_:).md)
