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

# 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.

## Declaration

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

## Parameters

- `url`: The URL of the document you wish to look up.

## Return Value

Return Value The newly created NSDocument object, or nil if the document could not be created.

## Discussion

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.

## See Also

### Creating and Opening Documents

- [duplicateDocument(withContentsOf:copying:displayName:)](appkit/nsdocumentcontroller/duplicatedocument(withcontentsof:copying:displayname:).md)
- [openDocument(withContentsOf:display:completionHandler:)](appkit/nsdocumentcontroller/opendocument(withcontentsof:display:completionhandler:).md)
- [openUntitledDocumentAndDisplay(_:)](appkit/nsdocumentcontroller/openuntitleddocumentanddisplay(_:).md)
- [makeDocument(for:withContentsOf:ofType:)](appkit/nsdocumentcontroller/makedocument(for:withcontentsof:oftype:).md)
- [makeDocument(withContentsOf:ofType:)](appkit/nsdocumentcontroller/makedocument(withcontentsof:oftype:).md)
- [makeUntitledDocument(ofType:)](appkit/nsdocumentcontroller/makeuntitleddocument(oftype:).md)
- [reopenDocument(for:withContentsOf:display:completionHandler:)](appkit/nsdocumentcontroller/reopendocument(for:withcontentsof:display:completionhandler:).md)
