Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

DeepBhavsar

macrumors newbie
Original poster
Mar 26, 2009
2
0
Hi Everyone

I am new to MAC Programming. I have just spend two days in it. Now, I have created simple Screen saver project from XCode.

I have put my all required images in the Resource folder of my project. Now,I want to access those images in my code. I don't know how to access these images from resource folder.

If I use Absolute path then it works fine, but when I uses any other relative path it doesn't work. Can you tell me what will be relative path for my images?

Assume I have "test.jpg" file in my resource folder of Screensaver project. When I will build the project,it will give me (TestScreenSaver.saver) file.

What will be my relative path for this project.



I will appreciate any help.

Thanks and Regards
-----------------------
Deep Bhavsar
 

kainjow

Moderator emeritus
Jun 15, 2000
7,958
7
Normally you'd use
Code:
NSString *imagePath = [[NSBundle mainBundle] pathForImageResource:@"test.jpg"];
but mainBundle would return the bundle of whatever is loading your screensaver plugin, so try
Code:
NSString *imagePath = [[NSBundle bundleForClass:[self class]] pathForImageResource:@"test.jpg"];
 

DeepBhavsar

macrumors newbie
Original poster
Mar 26, 2009
2
0
Hi kainjow

Thanks for your valuable reply. I was trying with [NSBundle mainBundle] and it was not working.

I had tried with your code and I got my problem solved. :)



Thanks
----------------
Dipesh Bhavsar
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.