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

# openDocumentWithContentsOfURL:display:

Returns a document object created from the contents of a given URL and optionally displays it.

```
- (id) openDocumentWithContentsOfURL:(NSURL *) url display:(BOOL) display;
```

## Discussion

Returns an `NSDocument` object created from the contents of `aURL` and displays it if `flag` is <doc://com.apple.documentation/documentation/Swift/true>. The returned object is not retained, but is added to the receiver’s list of managed documents. Returns `nil` if the object could not be created, typically because `aURL` does not point to a valid location or because there is no `NSDocument` subclass for the document type. Even if `flag` is <doc://com.apple.documentation/documentation/Swift/true>, the document is not displayed if [`shouldCreateUI`](/documentation/AppKit/NSDocumentController/shouldCreateUI) returns <doc://com.apple.documentation/documentation/Swift/false>. This method calls [`makeDocumentWithContentsOfURL:ofType:`](/documentation/AppKit/NSDocumentController/makeDocumentWithContentsOfURL:ofType:) to obtain the created `NSDocument` object.

---

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)