Contents

beginOpenPanel(_:forTypes:completionHandler:)

Presents a nonmodal Open dialog that displays files you can open from a list of UTIs.

Declaration

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

Parameters

  • openPanel:

    The Open dialog to present.

  • inTypes:

    A list of file types that the user can choose from in the Open dialog.

  • completionHandler:

    The completion handler that runs when the user clicks the OK or Cancel button in the Open dialog.

    The block takes the following parameter:

    result

    Either Nsokbutton or Nscancelbutton, depending on which button the user clicks to dismiss the dialog.

Discussion

openDocument(_:) and beginOpenPanel(completionHandler:) call this method to do the actual work. You typically don’t call this method directly. Override this method as necessary to customize the Open dialog or to alter the list of UTIs in the inTypes parameter.

You can also override this method if you want to perform additional cleanup (for example, if you customize the Open dialog and need to tear down an accessory view). Your overridden implementation needs to call the underlying method on super, passing a custom completion handler. That handler does the additional cleanup work, and then calls the completion handler block that the caller provides.

See Also

Managing the Open Dialog