Class

NSSavePanel

An NSSavePanel object creates and manages a Save panel and allows you to run the panel in a modal loop. The Save panel provides a simple way for a user to specify a file to use when saving a document or other data. It can restrict the user to files of a certain type, as specified by an extension.

Overview

An NSSavePanel object manages a panel that allows users to specify the directory and name under which a file is saved. It supports browsing of the file system, and it accommodates custom accessory views.

An NSSavePanel object may have a delegate. The methods that delegates of NSSavePanel may implement are specified by the NSOpenSavePanelDelegate protocol.

In a sandboxed app, when a user saves a document, the Save dialog is presented by the powerbox, not AppKit. macOS then adds the saved file to the app’s sandbox (if necessary) to allow the app to write to the file.

Symbols

Configuring Panels

var accessoryView: NSView?

The custom accessory view for the current application.

var title: String!

The title of the panel.

var prompt: String!

The prompt of the default button.

var nameFieldLabel: String!

The string displayed in front of the filename text field.

var message: String!

The message text displayed in the save panel.

var canCreateDirectories: Bool

A Boolean value that indicates whether the panel allows the user to create directories.

var showsHiddenFiles: Bool

A Boolean value that indicates whether the panel displays files that are normally hidden from the user.

var showsTagField: Bool

A Boolean value that indicates whether the panel displays the Tags field.

var tagNames: [String]?

The tag names to set on the file the user has saved.

Configuring Panel Content

var isExtensionHidden: Bool

A Boolean value that indicates whether the extension-hiding checkbox is visible and checked.

var directoryURL: URL?

The directory shown in the panel as a URL.

var canSelectHiddenExtension: Bool

A Boolean value that indicates whether the panel allows the user to hide or show file extensions.

var allowedFileTypes: [String]?

An array of NSString objects specifying the allowed file types for the panel.

var allowsOtherFileTypes: Bool

A Boolean value that indicates whether the panel allows the user to save files with an extension that’s not in the list of allowed types.

var treatsFilePackagesAsDirectories: Bool

A Boolean value that indicates whether the panel displays file packages as directories.

Running Panels

func beginSheetModal(for: NSWindow, completionHandler: (Int) -> Void)

Presents the panel as a sheet modal to the specified window.

func begin(completionHandler: (Int) -> Void)

Presents the panel as a modeless window.

func runModal()

Displays the panel and begins its event loop with the current working (or last selected) directory as the default starting point.

func validateVisibleColumns()

Validates and possibly reloads the browser columns visible in the panel by invoking the delegate method panel:shouldShowFilename:.

Accessing User Selection

var url: URL?

The absolute pathname of the file currently shown in the panel as a URL.

var isExpanded: Bool

A Boolean value that indicates whether the panel is expanded.

var nameFieldStringValue: String

The user-editable filename currently shown in the name field.

Handling Actions

func ok(Any?)

This action method is invoked when the user clicks the panel’s OK button.

func cancel(Any?)

This action method is invoked when the user clicks the panel’s Cancel button.

Constants

Button tags

Button tags that refer to items on the panel.

Relationships

Inherits From