Re: Odd NSString behavior
Re: Odd NSString behavior
- Subject: Re: Odd NSString behavior
- From: Dave DeLong <email@hidden>
- Date: Wed, 24 Feb 2010 13:36:35 -0600
If the extra cocoa app is a resource in your main bundle, then it should be in Contents/Resources, not Contents/MacOS. If you put it in Contents/Resources, then you can retrieve it easily via:
NSString * linrgPath = [[NSBundle mainBundle] pathForResource:@"linrg2" ofType:@""];
The name "pathForResource" means that it's supposed to be finding the requested resource in the Resources folder (hence path for "Resource").
If for some strange reason it *must* be in the same directory as the current executable, then I would recommend using the executable path to find it:
NSString * linrgPath = [[[[NSBundle mainBundle] executablePath] stringByDeletingLastPathComponent] stringByAppendingPathComponent:@"linrg2"];
HTH,
Dave
On Feb 24, 2010, at 1:30 PM, McLaughlin, Michael P. 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;
>
> 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?
>
> FWIW, the full path expands to 104 chars and contains one space.
Attachment:
smime.p7s
Description: S/MIME cryptographic signature
_______________________________________________
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