Swift, get drive Icon

414 views Asked by At

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?

1

There are 1 answers

0
Code Different On BEST ANSWER

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")