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

# openDocument(_:)

An action method called by the Open menu command, it runs the modal Open panel and, based on the selected filenames, creates one or more `NSDocument` objects from the contents of the files.

```
@IBAction func openDocument(_ sender: Any?)
```

## Discussion

The method adds the newly created objects to the list of `NSDocument` objects managed by the document controller. This method calls [`openDocument(withContentsOf:display:completionHandler:)`](/documentation/AppKit/NSDocumentController/openDocument(withContentsOf:display:completionHandler:)), which actually creates the `NSDocument` objects.

## See Also

[`fileNamesFromRunningOpenPanel`](/documentation/AppKit/NSDocumentController/fileNamesFromRunningOpenPanel)

Returns a selection of files chosen by the user in the Open panel.



---

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)