Skip to content

Instantly share code, notes, and snippets.

@avighnash
Created March 31, 2019 03:42
Show Gist options
  • Save avighnash/0d4e780bd8477f24d9b6140bf325edbd to your computer and use it in GitHub Desktop.
Save avighnash/0d4e780bd8477f24d9b6140bf325edbd to your computer and use it in GitHub Desktop.
let filePicker = NSOpenPanel()
filePicker.canChooseFiles = false
filePicker.canChooseDirectories = true
filePicker.allowsMultipleSelection = false
filePicker.begin { (result) -> Void in
if result == NSApplication.ModalResponse.OK {
let fileManager = FileManager.default
do {
let fileURLs = try fileManager.contentsOfDirectory(at: filePicker.directoryURL!, includingPropertiesForKeys: nil)
self.images = fileURLs.map { NSImage(byReferencing: $0) }
}
catch {
print("Error while enumerating files \(filePicker.directoryURL!.path): \(error.localizedDescription)")
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment