• 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: Which approach is the best one
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Which approach is the best one


  • Subject: Re: Which approach is the best one
  • From: "Michael Ash" <email@hidden>
  • Date: Mon, 21 Aug 2006 12:08:06 -0400

On 8/21/06, Apparao <email@hidden> wrote:
Hi All,

        Is there any difference in the following Approaches:

        Approach 1:

                NSString *appPath = [[NSString stringWithString:@"~/Library/
Application Support/Application Name/"] stringByExpandingTildeInPath];

        Approach 2:

                NSString *appPath = [@"~/Library/Application Support/Application
Name/" stringByExpandingTildeInPath];

which approach is the best one to use?

There is no difference between approach 1 and 2. Doing [NSString stringWithString:@"..."] is entirely pointless, and I've never understood why people want to do it so much.

In any case, both of those approaches are bad, and the correct
approach is (typed in e-mail, not actually tested, etc.):

   FSRef appSupportRef;
   OSErr err = FSFindFolder(kUserDomain,
kApplicationSupportFolderType, 1, &appSupportRef);
   if(err != noErr)
       goto error;

   CFURLRef url = CFURLCreateFromFSRef(NULL, &appSupportRef);
   NSString *appSupportPath = [(id)url path];
   CFRelease(url);

   NSString *appSupportSubdir = [appSupportPath
stringByAppendingPathComponent:@"Application Name"];

Aside from being the Apple-approved way to get the path to Application
Support, it has the advantage of working correctly even if Application
Support hasn't been created yet (although you will have to take care
of creating your app's subdirectory yourself), and it will also work
if Apple should ever decide to change the location of Application
Support.

Mike
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: Which approach is the best one
      • From: Nir Soffer <email@hidden>
References: 
 >Which approach is the best one (From: Apparao <email@hidden>)

  • Prev by Date: any way to get or catch the last error generated by a running application through code
  • Next by Date: Re: Which approach is the best one
  • Previous by thread: Re: Which approach is the best one
  • Next by thread: Re: Which approach is the best one
  • Index(es):
    • Date
    • Thread