Instance Method

beginOpenPanel(_:forTypes:completionHandler:)

Presents a nonmodal Open dialog that displays files that can be opened based on a list of UTIs.

Declaration

func beginOpenPanel(_ openPanel: NSOpenPanel, forTypes inTypes: [String]?, completionHandler: @escaping (Int) -> Void)

Parameters

openPanel

The open panel to present.

inTypes

A list of file types that the user should be allowed to choose in the open panel.

completionHandler

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

The block takes the following parameter:

result

Either NSOKButton or NSCancelButton, depending on which button the user pressed to dismiss the dialog.

Discussion

This method is called by openDocument(_:) and beginOpenPanel(completionHandler:) to do the actual work. You typically do not call this method directly. You can override this method as needed to customize the Open panel or to alter the list of UTIs in the inTypes parameter.

You can also override this method if you to perform additional cleanup (for example, if you customized the open panel and need to tear down an accessory view). Your overridden implementation should call the underlying method on super, passing a custom completion handler. That handler should do the additional cleanup work, and then should call the completion handler block that was provided by the caller.

See Also

Managing the Open Dialog

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

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

func runModalOpenPanel(NSOpenPanel, forTypes: [String]?) -> Int

Presents a modal Open dialog and limits selection to specific file types.

var currentDirectory: String?

The directory path to be used as the starting point in the Open panel.

func urlsFromRunningOpenPanel() -> [URL]?

An array of URLs corresponding to the files selected in a running open panel.