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

# beginOpenPanel(completionHandler:)

Presents an Open dialog and delivers the results to a completion handler as an array of URLs for the chosen files, or nil.

```
func beginOpenPanel(completionHandler: @escaping ([URL]?) -> Void)
```

## Parameters

`completionHandler`

The completion handler that is called when the user clicks the OK or Cancel button in the open panel.

## Discussion

This method presents either a modal or nonmodal open panel, depending on which methods are overridden. Although you can call this method in other circumstances, this method is most commonly called by [`openDocument(_:)`](/documentation/AppKit/NSDocumentController/openDocument(_:)) in response to the user choosing Open… from the File menu.

If you override [`openDocument(_:)`](/documentation/AppKit/NSDocumentController/openDocument(_:)), you should typically call this method instead of calling [`beginOpenPanel(_:forTypes:completionHandler:)`](/documentation/AppKit/NSDocumentController/beginOpenPanel(_:forTypes:completionHandler:)) or [`urlsFromRunningOpenPanel()`](/documentation/AppKit/NSDocumentController/urlsFromRunningOpenPanel()) directly, because this method runs the modal panel in a way that is backwards compatible with subclasses that override [`runModalOpenPanel(_:forTypes:)`](/documentation/AppKit/NSDocumentController/runModalOpenPanel(_:forTypes:)) without overriding [`beginOpenPanel(_:forTypes:completionHandler:)`](/documentation/AppKit/NSDocumentController/beginOpenPanel(_:forTypes:completionHandler:)). Also, its completion handler determines which button the user pressed (to determine whether to return the array or `nil`) and orders out the open panel.

You can override this method to change the open panel presentation (adding an accessory view, for example) or change the UTI array that limits which files are selectable.

The default implementation of this method calls either [`urlsFromRunningOpenPanel()`](/documentation/AppKit/NSDocumentController/urlsFromRunningOpenPanel()) to run a modal open panel or [`beginOpenPanel(_:forTypes:completionHandler:)`](/documentation/AppKit/NSDocumentController/beginOpenPanel(_:forTypes:completionHandler:)) to begin a nonmodal open panel. If the user chooses to open files, the default implementation calls the completion handler with a `nil` array parameter. If the user cancels the Open dialog, the default implementation calls the completion handler with a `nil` array parameter.

If you override this method, your method should typically call the underlying method on `super` because of the additional code that it provides for free. Specifically, this method runs the modal panel in a way that is backwards compatible with subclasses that override [`runModalOpenPanel(_:forTypes:)`](/documentation/AppKit/NSDocumentController/runModalOpenPanel(_:forTypes:)) without overriding [`beginOpenPanel(_:forTypes:completionHandler:)`](/documentation/AppKit/NSDocumentController/beginOpenPanel(_:forTypes:completionHandler:)). Also, its completion handler determines which button the user pressed (to determine whether to return the array or `nil`) and orders out 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)