Instance Property

allowedFileTypes

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

Declaration

var allowedFileTypes: [String]? { get set }

Discussion

The value of this property specifies the file types the user can save the file as. A file type can be a common file extension, or a UTI. The default value of this property is nil, which indicates that any file type can be used. (Note that if the array is not nil and the array contains no items, an exception is raised.)

If no extension is given by the user, the first item in the allowedFileTypes array will be used as the extension for the save panel. If the user specifies a type not in the array, and allowsOtherFileTypes is true, they will be presented with another dialog when prompted to save.

NSOpenPanel: In versions of macOS earlier than v10.6, this property is ignored. For applications that link against v10.6 and higher, this property determines which files should be enabled in the open panel. You should not use the deprecated methods to show the open panel (that is, the methods that take a types: parameter) because they will overwrite this value. The allowed file types can be changed while the panel is running (for example, from an accessory view). This is also known as the “enabled file types.” A nil value indicates that all files should be enabled.

See Also

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 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.