forked from jerrykrinock/CategoriesObjC
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNSBundle+AppIcon.m
19 lines (16 loc) · 887 Bytes
/
NSBundle+AppIcon.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#import "NSBundle+AppIcon.h"
@implementation NSBundle (AppIcon)
- (NSImage*)appIcon {
// Oddly, I can't find a constant for the bundle icon file.
// Compare to kCFBundleNameKey, which is apparently "CFBundleName".
NSString* iconFilename = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleIconFile"] ;
// I do not use -pathForImageResource, in case the Resources also contains
// an image file, for example a png, with the same name. I want the .icns.
NSString* iconBasename = [iconFilename stringByDeletingPathExtension] ;
NSString* iconExtension = [iconFilename pathExtension] ; // Should be "icns", but for some reason it's in Info.plist
NSString* iconPath = [[NSBundle mainBundle] pathForResource:iconBasename
ofType:iconExtension] ;
NSImage* appIcon = [[NSImage alloc] initWithContentsOfFile: iconPath] ;
return [appIcon autorelease] ;
}
@end