一. 前言
打开面板,提示用户选择要打开的文件。
@interface NSOpenPanel : NSSavePanel

Overview
Apps use the Open panel as a convenient way to query the user for the name of a file to open. In macOS 10.15 and later, the system always draws Open panels in a separate process, regardless of whether the app is sandboxed. When the user chooses a file to open, macOS adds that file to the app’s sandbox. Prior to macOS 10.15, the system drew the panels in a separate process only for sandboxed apps.
应用程序使用“打开”面板作为方便的方法来查询用户要打开的文件的名称。在macOS 10.15及更高版本中,系统始终在单独的过程中绘制“打开”面板,而不管该应用程序是否被沙箱化。当用户选择要打开的文件时,macOS将该文件添加到应用的沙箱中。在macOS 10.15之前,系统仅在沙盒应用程序的单独过程中绘制面板。
二. 官方属性方法
1. 创建打开面板
+ (NSOpenPanel *)openPanel; // 创建NSOpenPanel实例对象,但是这个类不是单例。
2. 配置打开面板
// 是否解析别名
@property BOOL resolvesAliases;
// 是否可以选择目录
@property BOOL canChooseDirectories;
// 是否可以选择多个文件或目录
@property BOOL allowsMultipleSelection;
// 是否选择文件
@property BOOL canChooseFiles;
// 附件视图是否可见
@property (getter=isAccessoryViewDisclosed) BOOL accessoryViewDisclosed API_AVAILABLE(macos(10.11));
3. iCloud
// 指示面板如何响应具有冲突版本的iCloud文档
@property BOOL canResolveUbiquitousConflicts API_AVAILABLE(macos(10.10));
// 指示面板如何响应未完全本地下载的iCloud文档
@property BOOL canDownloadUbiquitousContents API_AVAILABLE(macos(10.10));
4. 访问用户选择
// URL数组,每个URL包含所选文件或目录的完整指定位置。
@property (readonly, copy) NSArray<NSURL *> *URLs;