Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I load an NSImage representation of the icon for my application?

I have a custom icon file (MyApp.icns) set up for my Cocoa App. How can I access an NSImage representation of the icon from within my application?

Something like the following would be perfect:

NSImage * iconImage = [MyApplication defaultIconAsImage];

But I'm sure it isn't that easy :)

I can, of course, get a path to the icon file as follows:

NSString * iconPath = [[NSBundle mainBundle]
                       pathForResource:@"MyApp" ofType:@"icns"];

But it seems to me that there should be some kind of standard way to access the icon file for the application, other than calling it by name, since the name could change.

What is the proper way to do this?

like image 997
e.James Avatar asked Aug 31 '09 19:08

e.James


1 Answers

[NSApp applicationIconImage]

like image 148
Chuck Avatar answered Nov 13 '22 09:11

Chuck