Created
March 31, 2019 03:42
-
-
Save avighnash/0d4e780bd8477f24d9b6140bf325edbd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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