Instance Method

panel(_:userEnteredFilename:confirmed:)

Tells the delegate that the user confirmed a filename choice by clicking Save in a Save panel.

Declaration

optional func panel(_ sender: Any, userEnteredFilename filename: String, confirmed okFlag: Bool) -> String?

Parameters

sender

The panel reporting the user’s confirmation of a filename choice.

filename

The user’s filename choice.

okFlag

If true, the user clicked the Save button; if false, the user did not.

Return Value

You can either leave the filename alone, or return nil to cancel the save and leave the Save panel as is. (If your app is not running in a sandbox, you can also sanitize the filename to remove undesirable characters, limit its length, and so on.)

This method is called before any required extension is appended to the filename and before the Save panel asks the user to replace an existing file, if applicable.

This method may be called multiple times in the sessions as the user types. In those cases, okFlag will be false until the user confirms the choice, in which case okFlag will become true. If the delegate does extensive validation or puts up alerts, it should do so only when okFlag is true.

See Also

Running Panels

func panel(Any, shouldEnable: URL)

For NSOpenPanel delegates, asks the delegate whether the specified URL should be enabled in the panel. This method is not called for NSSavePanel delegates; all URLs are always disabled.

func panel(Any, validate: URL)

For NSSavePanel delegates, asks the delegate for file URL validation when the user chooses the Save button. For NSOpenPanel delegates, asks the delegate for file URL validation once for each selected filename (or directory) when the user chooses the Open button.

func panel(Any, didChangeToDirectoryURL: URL?)

Informs the delegate that the user changed the selected directory to the directory located at the specified URL. The URL may be nil if the current URL can’t be represented by an NSURL object.

func panel(Any, willExpand: Bool)

Tells the delegate that the Save panel is about to expand or collapse because the user clicked the disclosure triangle that displays or hides the file browser.

func panelSelectionDidChange(Any?)

Tells the delegate that the user changed the selection in the specified Save panel.