Uli's Web Site
[ Zathras.de - Uli's Web Site ]
Other Sites: Stories
Pix
Abi 2000
Stargate: Resurgence
Lost? Site Map!
 
 
     home | blog | moose | programming | articles >> blog

 Blog Topics
 
 Archive
 

15 Most Recent [RSS]

 Less work through Xcode and shell scripts
2011-12-16 @600
 
 iTunesCantComplain released
2011-10-28 @954
 
 Dennis Ritchie deceased
2011-10-13 @359
 
 Thank you, Steve.
2011-10-06 @374
 
 Cocoa Text System everywhere...
2011-03-27 @788
 
 Blog migration
2011-01-29 @520
 
 All you need to know about the Mac keyboard
2010-08-09 @488
 
 Review: Sherlock
2010-07-31 @978
 
 Playing with Objective C on Debian
2010-05-08 @456
 
 Fruit vs. Obst
2010-05-08 @439
 
 Mixed-language ambiguity
2010-04-15 @994
 
 Uli's 12:07 AM Law
2010-04-12 @881
 
 Uli's 1:24 AM Law
2010-04-12 @874
 
 Uli's 6:28 AM Law
2010-04-12 @869
 
 Uli's 3:57 PM Law
2010-04-12 @867
 

More...

Getting standard system icons in Cocoa

Sometimes the solution to a problem is so easy you feel like an utter and complete moron not for thinking of it before. See, for quite a while I've been tracking down standard system icons on my hard disk and adding them to my apps that needed to use them. Then, one day, Shawn Erickson (who is much smarter than me but not as grumpy on mailing lists, which is probably why his name might not ring a bell immediately, even though it should) comes along and not only points our collective noses at NSWorkspace's iconForFileType: method, but also shows us that the NSFileTypeForHFSTypeCode() function that's used to specify HFS type codes to NSOpenPanel and family will also work with that.

So, with a smattering of Carbon knowledge, you immediately realise that the entirety of Carbon's Icons.h header (part of HIServices.framework and thus available in every Cocoa app) has been available to you for ages but you didn't write cunning lines of code like:

NSImage* folderIcon = [[NSWorkspace sharedWorkspace] iconForFileType: NSFileTypeForHFSTypeCode(kGenericFolderIcon)];
or
NSImage* macIcon = [[NSWorkspace sharedWorkspace] iconForFileType: NSFileTypeForHFSTypeCode(kComputerIcon)];
I've known for a while that being stupid really does hurt, but I didn't expect to be able to measure it in bytes one day...

Reader Comments: (RSS Feed)
Peter Hosey writes:
On the other hand, using Icon Services does let you access the icons of other applications (e.g. 'MP3 '/'hook' == iTunes' MP3 icon). That said, yes, NSFileTypeForHFSTypeCode is definitely your friend. :) What I would really like is the ability to set an image view's image by file type in IB. That would make it easy to put a caution icon (for example) in a dialog box.
Or E-Mail Uli privately.

 
Created: 2006-08-01 @218 Last change: 2024-11-15 @656 | Home | Admin | Edit
© Copyright 2003-2024 by M. Uli Kusterer, all rights reserved.