Reputation: 49
Swift 4 / Xcode 9.2 / OS X 10.12
I am trying to use a NSOpenPanel to get a jpg/png file with the following code, but not able to open panel for choose image, no crash, nothing happened.
let openPanel = NSOpenPanel()
openPanel.allowsMultipleSelection = false
openPanel.canChooseDirectories = false
openPanel.canCreateDirectories = false
openPanel.canChooseFiles = true
openPanel.allowedFileTypes = ["jpg","png"]
openPanel.beginSheetModal(for: self.view.window!) { (result) in
}
Upvotes: 4
Views: 1693
Reputation: 6857
Give your app access to user selected files under
Capabilities -> App Sandbox -> File Access -> User Selected File
Upvotes: 5
Reputation: 285200
In Xcode 9 apps are sandboxed by default.
You have to enable Read/Write
access of User Selected File in the Capabilities tab
Upvotes: 2