Question

I have a ScreenSaver project. In the Resources of this project presents the image file. I'm trying to load it like this:

NSString* imageName = [[NSBundle mainBundle] pathForResource:@"DefaultImage" ofType:@"jpg"];
mpCurrentImage = [[NSImage alloc] initWithContentsOfFile:imageName];

But the path of mainBundle is /Applications/System Preferences.app/Contents/Resources

How to get the path to the .saver bundle, to load the image from recourses?

Was it helpful?

Solution

You'd want to use

NSString* imageName = [[NSBundle bundleForClass:[self class]] pathForResource:@"DefaultImage" ofType:@"jpg"];

assuming that this code is in a class belonging to the bundle.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top