NSDocumentController::openDocument(_:)
An action method called by the Open menu command, it runs the modal Open panel and, based on the selected filenames, creates one or more NSDocumentobjects from the contents of the files.
Declaration
@IBAction func openDocument(_ sender: Any?)Discussion
The method adds the newly created objects to the list of NSDocument objects managed by the document controller. This method calls openDocument(withContentsOf:display:completionHandler:), which actually creates the NSDocument objects.
urlsFromRunningOpenPanel()
An array of URLs corresponding to the files selected in a running open panel.
Declaration
func urlsFromRunningOpenPanel() -> [URL]?Discussion
Accessing this property creates an NSOpenPanel object and runs it using the runModalOpenPanel(_:forTypes:) method. When the user dismisses the panel, the returned value is an array of URLs corresponding to the files chosen by the user. The value is nil if the user cancels the Open panel or makes no selection.
新建文档使用:
Button("New Project") { NSDocumentController.shared.newDocument(nil) }