13

I'm writing a Cocoa application that displays the contents of an archive file in an NSOutlineView. I provide a custom icon for an NSBrowserCell in the outline column, and it works great, but I ran into a little snag — using [NSImage imageNamed:@"NSFolder"] returns the correct image (a generic folder icon) on 10.6, but on 10.5 it returns nil, so all the folder icons disappear. (I can't find any documentation on the NSFolder icon name to see when it was introduced — I got it working by trial and error.)

Is there a non-deprecated method for getting a generic folder icon that works on both 10.5 and 10.6?

Quinn Taylor
  • 44,553
  • 16
  • 113
  • 131

1 Answers1

21

[[NSWorkspace sharedWorkspace] iconForFileType:NSFileTypeForHFSTypeCode(kGenericFolderIcon)]

(I think)

Wevah
  • 28,182
  • 7
  • 83
  • 72
  • 3
    (FWIW, NSImageNameFolder (which I assume is @"NSFolder") was introduced in 10.6.) – Wevah Sep 18 '09 at 00:36
  • 3
    Thank you! I learn something new about Cocoa at least once a week... I wouldn't have thought to look in NSImage.h for constants like `NSImageNameFolder`, and never knew about `kGenericFolderIcon`, which is one of many constants defined in IconsCore.h, part of LaunchServices.framework. That's definitely nice to know about. – Quinn Taylor Sep 18 '09 at 03:18
  • And how did Google not give this to me when I asked for "Cocoa generic folder icon"?! http://cocoadev.com/index.pl?GetGenericFolderIcon I should have picked up the code on RedSweaterBlog, but it was running into the sidebar and I missed it... – Quinn Taylor Sep 18 '09 at 03:30
  • 1
    How about the icon for "empty file"? or "picture"? – Nicolas Miari Sep 13 '17 at 08:02