Mailing Lists: Apple Mailing Lists
Image of Mac OS face in stamp
Re: NSURL-based replacement for NSTemporaryDirectory()?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSURL-based replacement for NSTemporaryDirectory()?



On Apr 5, 2012, at 5:59 PM, Sean McBride wrote:

> Hi all,
>
> I'm trying to get rid of the last bits of NSString path-based file code, and am looking to replace NSTemporaryDirectory().
>
> I've tried this:
>
> NSError* error = nil;
> NSURL* url = [fileManager URLForDirectory:NSItemReplacementDirectory
>                                 inDomain:NSUserDomainMask
>                        appropriateForURL:nil
>                                   create:YES
>                                    error:&error];
>
> but it returns nil (with no error, bah).  If I pass something for 'appropriateForURL', it does work, but what to pass when you just want any old temp directory?
>
> (Since someone will ask: my exact usage case is in unit test code, I need to test a file reader/writer, and just need a place to dump my files.)

NSItemReplacementDirectory isn’t what you want either; that’s supposed to be used for implementing a safe save feature, IIRC.

Probably your best bet is [NSURL fileURLWithPath:NSTemporaryDirectory()]. It’s not ideal, but I think it’s the best we’ve got at the moment. I actually still use the FSFindFolder() API and then use CFURLCreateFromFSRef() to get a URL, but that’s looking less and less like a good solution these days. I actually filed a radar report on this last week (rdar://11142974); there are actually quite a lot of directories that are not available via -URLForDirectory:inDomain:bla:bla:bla: that were available via the older FSFindFolder() API, many of which were quite useful. A few of them are:

kPreferencesFolderType
kTemporaryFolderType
kVolumeRootFolderType
kCurrentUserFolderType
kDomainTopLevelFolderType
kUtilitiesFolderType
kFontsFolderType
kQuickLookFolderType
kWidgetsFolderType
kScreenSaversFolderType
kServicesFolderType

And a whole lot more. Feel free to file a radar report yourself if you agree that -URLForDirectory:etc:etc:etc:etc: needs to be beefed up; Apple uses duplicate radar reports to prioritize fixes.

Charles

_______________________________________________

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: 
 >NSURL-based replacement for NSTemporaryDirectory()? (From: Sean McBride <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2011 Apple Inc. All rights reserved.