• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Loading images from subfolder of Resources
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Loading images from subfolder of Resources


  • Subject: Re: Loading images from subfolder of Resources
  • From: Ricky Sharp <email@hidden>
  • Date: Thu, 20 Jan 2005 21:33:41 -0600


On Jan 20, 2005, at 9:20 PM, M. Uli Kusterer wrote:

At 19:34 Uhr -0600 20.01.2005, Ricky Sharp wrote:
NSString* theImagePath = [NSBundle pathForResource:aName ofType:nil
inDirectory:[[aBundle resourcePath] stringByAppendingPathComponent:@"Images"]];


where aName is the root name of some image and aBundle is usually the result of [NSBundle mainBundle].

However, theImagePath is always nil.

This is wrong. You need to drink more black tea (or coffee, if you're so inclined) before coding. :-)


pathForResource is an instance method, IIRC, so the first NSBundle should be aBundle.

There are two variations; one class method and one instance method. I've tried both without success.


Second, pathForResource is there for building the path, why would you pass the path to your image folder and the file name to NSBundle??? Just pass the name there instead.

When the images lived directly inside of the Resources folder, just passing the name was good enough. From my original post, I had mentioned I used pathForResource:ofType:. But now, I'm placing images in subfolders. Because I don't always know the extension, that's why I need to pass the root name of the image along with the folder that they live in. Furthermore, these functions do not recurse into any subfolders; that's why I need to specify the exact folder to look in.


I'm also not sure you're allowed to pass NIL for the type. Certainly the docs don't mention that.

The docs do mention that nil (or the empty string) can be used. This instructs the method to search for the first resource that matches the name, regardless of extension.


I've since coded up a small test that uses pathsForResourcesOfType:inDirectory: The following provides me with all paths to all of my images (regardless of extension):

NSArray* theImageResourcePaths =
[[NSBundle mainBundle] pathsForResourcesOfType:nil inDirectory:@"Images"];


I'm now thinking that it's a bug that pathForResource:ofType:inDirectory: fails when ofType is set to nil. Will write this up soon.

Finally, I think I'm going to redo things a bit to use the paths returned by pathsForResourcesOfType. This seems to be a better workaround since it will allow for any image type (i.e. any image extension).

___________________________________________________________
Ricky A. Sharp         mailto:email@hidden
Instant Interactive(tm)   http://www.instantinteractive.com

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: Loading images from subfolder of Resources
      • From: Andreas Mayer <email@hidden>
    • Re: Loading images from subfolder of Resources
      • From: "M. Uli Kusterer" <email@hidden>
References: 
 >Loading images from subfolder of Resources (From: Ricky Sharp <email@hidden>)
 >Re: Loading images from subfolder of Resources (From: "M. Uli Kusterer" <email@hidden>)

  • Prev by Date: Re: How to get text coordinates in a NSTableView
  • Next by Date: Re: Loading images from subfolder of Resources
  • Previous by thread: Re: Loading images from subfolder of Resources
  • Next by thread: Re: Loading images from subfolder of Resources
  • Index(es):
    • Date
    • Thread