If I have a file, I can get the icon by doing something such as:
NSImage *iconImage = [[NSWorkspace sharedWorkspace] iconForFile: @\"myFile.png\"];
Here is the Swift 5 version of Dave DeLong's answer:
icon(forFile:)
Returns an image containing the icon for the specified file.
Declaration
func icon(forFile fullPath: String) -> NSImage
Parameters
fullPath
- The full path to the file.
icon(forFileType:)
Returns an image containing the icon for files of the specified type.
Declaration
func icon(forFileType fileType: String) -> NSImage
Parameters
fileType
- The file type, which may be either a filename extension, an encoded HFS file type, or a universal type identifier (UTI).