Re: pathForResource with nil Type
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.