swiftdrives

Swift, get drive Icon


I was looking for a way to display icons for the mounted drives and also for specific folders. I read all the documentation of NSWorkspace and I found this code but I'm not able to use it to get the icon for a mounted volume.

let icon = NSWorkspace.shared().icon(forFile: path.absoluteString)

So is there any method to get the icon of the Macintosh HD drive?


Solution

  • It's just a matter of getting the right path. Disk volumes are mounted under /Volumes:

    let icon = NSWorkspace.shared().icon(forFile: "/Volumes/Macintosh HD")