<!--
{
  "availability" : [
    "macCatalyst: -",
    "macOS: 10.4.0 - 10.7.0"
  ],
  "documentType" : "symbol",
  "framework" : "AppKit",
  "identifier" : "/documentation/AppKit/NSDocumentController/openDocumentWithContentsOfURL:display:error:",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "AppKit"
    ],
    "preciseIdentifier" : "c:objc(cs)NSDocumentController(im)openDocumentWithContentsOfURL:display:error:"
  },
  "title" : "openDocumentWithContentsOfURL:display:error:"
}
-->

# openDocumentWithContentsOfURL:display:error:

Opens a document located by the given URL presents its user interface if requested, and returns the document if successful.

```
- (id) openDocumentWithContentsOfURL:(NSURL *) url display:(BOOL) displayDocument error:(NSError **) outError;
```

## Discussion

If not  successful, the method returns `nil` after setting `outError` to point to an `NSError` object that encapsulates the reason why the document could not be opened.

The default implementation of this method checks to see if the document is already open according to [`document(for:)`](/documentation/AppKit/NSDocumentController/document(for:)-i5zi), and if it is not open determines the type of the document, calls [`makeDocument(withContentsOf:ofType:)`](/documentation/AppKit/NSDocumentController/makeDocument(withContentsOf:ofType:)) to instantiate it, then calls [`addDocument(_:)`](/documentation/AppKit/NSDocumentController/addDocument(_:)) to record its opening, and sends the document [`makeWindowControllers()`](/documentation/AppKit/NSDocument/makeWindowControllers()) and [`showWindows()`](/documentation/AppKit/NSDocument/showWindows()) messages if `displayDocument` is <doc://com.apple.documentation/documentation/Swift/true>. If the document is already open it is just sent a [`showWindows()`](/documentation/AppKit/NSDocument/showWindows()) message if `displayDocument` is <doc://com.apple.documentation/documentation/Swift/true>.

---

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)