• 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: pathForResource with nil Type
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: pathForResource with nil Type


  • Subject: Re: pathForResource with nil Type
  • From: Andy Lee <email@hidden>
  • Date: Tue, 10 Sep 2002 13:43:14 -0400

At 6:14 PM +0100 9/10/02, Jeremy Dronfield wrote:
path = [[NSBundle mainBundle] pathForResource:fileToGet ofType:@""];
[textView readRTFDFromFile:path];

RUN LOG ERROR:
-[NSURL initFileURLWithPath:]: must supply a non=empty path

The reason I want to do this, BTW, is so I can load either rtf or rtfd files into textView with the same method. Why isn't -pathForResource: finding my resource files?

If you don't specify a type, you must put the whole file name in the first argument, including the file extension. Unless there's some smarter technique I don't know about, you'll have to do two separate calls, something like this:

path = [[NSBundle mainBundle] pathForResource:fileToGet ofType:@"rtf"];
if (path == nil)
{
path = [[NSBundle mainBundle] pathForResource:fileToGet ofType:@"rtfd"];
}

If this pattern comes up a lot in your code, you could add a category to NSBundle that wraps the above in a single method, something like...

(NSString *)pathForResource:(NSString *)name
ofType:(NSString *)extension1
orType:(NSString *)extension2;

... and/or...

(NSString *)pathForResource:(NSString *)name
ofTypeInArray:(NSArray *)extensions;

--Andy
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

  • Follow-Ups:
    • Re: pathForResource with nil Type
      • From: Jeremy Dronfield <email@hidden>
References: 
 >pathForResource with nil Type (From: Jeremy Dronfield <email@hidden>)

  • Prev by Date: Re: IB and smb volumes
  • Next by Date: Getting NSView mousedown event postion?
  • Previous by thread: pathForResource with nil Type
  • Next by thread: Re: pathForResource with nil Type
  • Index(es):
    • Date
    • Thread