• 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: Odd NSString behavior
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Odd NSString behavior


  • Subject: Re: Odd NSString behavior
  • From: "McLaughlin, Michael P." <email@hidden>
  • Date: Wed, 24 Feb 2010 15:15:18 -0500
  • Acceptlanguage: en-US
  • Thread-topic: Odd NSString behavior

Thank you to all who responded.

I like this solution.  I also replaced

myBundle

with [NSBundle mainBundle] directly.


On 2/24/10 3:06 PM, "Sherm Pendley" <email@hidden> wrote:

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



--
Mike McLaughlin
_______________________________________________

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

References: 
 >Re: Odd NSString behavior (From: Sherm Pendley <email@hidden>)

  • Prev by Date: Re: Odd NSString behavior
  • Next by Date: Re: Getting relative day-of-week name?
  • Previous by thread: Re: Odd NSString behavior
  • Next by thread: Getting relative day-of-week name?
  • Index(es):
    • Date
    • Thread