The only way to get images from asset catalogs in frameworks is by using private APIs.
Was just about to ask the exact same question. UIImage has constructors that take a bundle as a param (not sure if they work with an AC, but I imagine they do), too bad OS X didn't get the same love.
It'd be nice if NSBundle's URLForImageResource: method worked with images in an Asset catalog, but it does not. I tried this:
NSURL *patternedBackgroundImageURL = [bundle URLForImageResource:@"PatternedBGImage"]; NSImage *windowBackgroundColorImage = [[NSImage alloc]initWithContentsOfURL:patternedBackgroundImageURL];
I filed a bug
Actually you can use an Asset Catalog with frameworks. I heard back on that bug report.
You need to use NSBundle's imageForResource: method.
NSBundle *bundle = [NSBundle bundleForClass:[self class]]; NSImage *image = [bundle imageForResource:@"ImageNameInAssetCatalog"];
Aha! Yeah, I also tried using -URLForImageResource: with an equal lack of success. I ended up just moving everything out of the asset catalog and using traditional resources, but you're right: -imageForResource: works!
Oddly enough, I haven't heard a peep about my radar (#24090114), but if I recall correctly, I filed mine as an enhancement request, not a bug. Maybe they pay less attention to enhancement requests.
Great solution — thank you.
This is returning nil on OS X 10.9.
There is also