views:

428

answers:

1

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?

+6  A: 

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

(I think)

Wevah
(FWIW, NSImageNameFolder (which I assume is @"NSFolder") was introduced in 10.6.)
Wevah
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
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