NSOpenPanel的'urls'变量可以为空吗?

时间:2018-03-19 23:48:59

标签: swift macos cocoa appkit nsopenpanel

我在我的应用程序中显示NSOpenPanel,如下所示:

let openPanel = NSOpenPanel()
    openPanel.canChooseFiles = true
    openPanel.canChooseDirectories = true
    openPanel.allowsMultipleSelection = true
    openPanel.beginSheetModal(for: self.window!, completionHandler: { returnCode in
        if returnCode == NSApplication.ModalResponse.OK {
            let chosenItems = openPanel.urls
            if chosenItems.isEmpty { return }
            else { self.startSlideshow(rootURLS: chosenItems) }
        }
    })

我想知道openPanel.urls是否可以为空/如果我应该为错误消息实现表单,或者如果我可以假设它总是包含一些值。我试过简单地在面板中选择任何东西。因此,openPanel.urls只包含面板显示的目录,这就是我认为它可能永远不会为空的原因。此外,我确实意识到面板的“打开”按钮有时会被取消激活,大概是在没有返回网址的情况下(?)。

我希望有人在这里有更多的经验,并且可能能告诉我实际上是这样的情况,或者我在这里非常错误。

0 个答案:

没有答案