Re: Odd NSString behavior
Re: Odd NSString behavior
- Subject: Re: Odd NSString behavior
- From: Sherm Pendley <email@hidden>
- Date: Wed, 24 Feb 2010 15:06:27 -0500
On Wed, Feb 24, 2010 at 2:30 PM, McLaughlin, Michael P. <email@hidden> wrote:
> This is just a minor glitch but I hate loose ends.
>
> I have a Cocoa app as a resource in my MainBundle. If I try to get its
> executable via the obvious
>
> NSString * linrgPath = [myBundle pathForResource:
> @"linrg2.app/Contents/MacOS/linrg2" ofType: @""];
>
> then linrgPath is nil;
Seems reasonable - pathForResource:ofType: is probably respecting the
fact that linrg2.app is itself a bundle, and refusing to look around
inside of it.
> However, if I split the path into two pieces it works as intended.
>
> NSString * linrgPath = [myBundle pathForResource: @"linrg2.app" ofType:
> @""];
> linrgPath = [linrgPath stringByAppendingString:@"/Contents/MacOS/linrg2"];
>
> Is this reasonable?
It could be better, IMHO. The type of your resource is "app", and you
shouldn't hard-code the location of the executable within it. I'd
create another NSBundle instance to represent the resource app, then
ask that bundle for the path to its executable, something like this:
NSBundle *linrgBundle = [NSBundle bundleWithPath:[myBundle
pathForResource:@"linrg2" ofType:@"app"]];
NSString *linrgExecutable = [linrgBundle executablePath];
sherm--
--
Cocoa programming in Perl:
http://www.camelbones.org
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden