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

# document(for:)

Returns, for a given URL, the open document whose file or file package is located by the URL, or `nil` if there is no such open document.

```
func document(for url: URL) -> NSDocument?
```

## Parameters

`url`

The URL of the document you wish to look up.

## Return Value

The newly created [`NSDocument`](/documentation/AppKit/NSDocument) object, or `nil` if the document could not be created.

## Discussion

The default implementation of this method queries each open document to find one whose URL matches, and returns the first one whose URL does match.

---

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)