---
title: "reopenDocument(for:withContentsOf:display:completionHandler:)"
framework: appkit
role: symbol
role_heading: Instance Method
path: "appkit/nsdocumentcontroller/reopendocument(for:withcontentsof:display:completionhandler:)"
---

# reopenDocument(for:withContentsOf:display:completionHandler:)

Reopens a document, optionally located by a URL, by reading the contents for the document from another URL, optionally presents its user interface, and calls the passed-in completion handler.

## Declaration

```swift
func reopenDocument(for urlOrNil: URL?, withContentsOf contentsURL: URL, display displayDocument: Bool, completionHandler: @escaping (NSDocument?, Bool, (any Error)?) -> Void)
```

```swift
func reopenDocument(for urlOrNil: URL?, withContentsOf contentsURL: URL, display displayDocument: Bool) async throws -> (NSDocument, Bool)
```

## Parameters

- `urlOrNil`: The URL locating the reopened document, unless nil. A nil parameter value indicates that the reopened document is to have no doc://com.apple.appkit/documentation/AppKit/NSDocument/fileURL, like an untitled document.
- `contentsURL`: The URL (which may or may not be different from the URL of the reopened document) of the document from which the contents are read.
- `displayDocument`: If doc://com.apple.documentation/documentation/Swift/true, displays the document’s user interface.
- `completionHandler`: The completion handler block object passed in to be called at some point in the future, perhaps after the method invocation has returned. The completion handler must be called on the main thread. The block takes three arguments:

## Discussion

Discussion The default implementation of this method is very similar to openDocument(withContentsOf:display:completionHandler:), the primary difference being that it calls makeDocument(for:withContentsOf:ofType:) instead of makeDocument(withContentsOf:ofType:). You can override this method to customize how documents are reopened during application launching by the restorable state mechanism introduced in OS X v10.7. Its implementation, however, is somewhat complex, so you should generally investigate overriding one of the methods that it calls instead. However, you can override this method to do additional work before calling the underlying method on super. You can also call the underlying method on super with a custom completion handler that performs additional work before calling the original completion handler. Applications probably do not need to call this method directly. For backward binary compatibility with OS X v10.6 and earlier, the default implementation of this method calls [self reopenDocumentForURL:url withContentsOfURL:contentsURL error:&anError] if that method is overridden and this one is not, instead of calling makeDocument(for:withContentsOf:ofType:) and all the rest.

## See Also

### Creating and Opening Documents

- [document(for:)](appkit/nsdocumentcontroller/document(for:)-i5zi.md)
- [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)
