Re: Which approach is the best one
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