On 11/02/2010, at 2:44 PM, Paul Johnson wrote:

> I'm trying to find a best way to create the Application Support
> folder. I'm rather new at Cocoa so it's taking me a while to do even
> this simple thing. I'm also interested in ensuring my application can
> be localized easily.
> 
> I have a function "- (NSString *)applicationSupportFolder" that
> returns the desired folder name, properly localized. I call this
> function and then use NSFileManager to check for the existence of the
> folder. Because there can be a file (NOT a folder) already bearing the
> folder name, I need to handle that possibility. Everything I've found
> on the internet just ignores this case.
> 
> Can anyone recommend what I should do?


It depends. If there is a file bearing that name - unlikely, really - then what 
do you want to do about it? You could delete it, or you could just choose 
another name for your folder. Either way, NSFileManager has methods to do what 
you want. Renaming you can handle yourself - just keep renaming until you get a 
clear outcome that meets your needs (appending digits is a simple way). 
[NSFileManager fileExistsAtPath:isDirectory:] can tell you whether you're 
looking at a file or folder.

For the rename situation, your -applicationSupportFolder method (why not make 
it a class method?) can do all the work internally to make sure that the folder 
is valid, belongs to you, created if necessary and so on, so clients of it can 
just use the method to work with the folder, safe in the knowledge that there's 
no more to do.

Also, presumably you are returning the name of YOUR unique application support 
folder with the ~Library/Application Support directory. That folder can be 
found using NSApplicationSupportDirectory, then you usually will put your own 
folder inside this. If your folder uses your app's bundle identifier, it will 
almost certainly not collide with anyone else's. However, a much earlier 
discussion on that seemed to indicate that most people use the application 
name, which might not be quite so guaranteed to be unique.

--Graham


_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to