Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added temporary path handling

  • Loading branch information...
commit 84ee85088b2028e1992d72010b2b25d8e8d2e3b6 1 parent 0c6b842
@Cocoanetics authored
View
7 Core/Source/DTAsyncFileDeleter.m
@@ -7,6 +7,7 @@
//
#import "DTAsyncFileDeleter.h"
+#import "NSString+DTPaths.h"
static dispatch_queue_t _delQueue;
@@ -59,11 +60,7 @@ - (void)waitUntilFinished
- (void)removeItemAtPath:(NSString *)path
{
// make a unique temporary name in tmp folder
- CFUUIDRef newUniqueId = CFUUIDCreate(kCFAllocatorDefault);
- CFStringRef newUniqueIdString = CFUUIDCreateString(kCFAllocatorDefault, newUniqueId);
- NSString *tmpPath = [NSTemporaryDirectory() stringByAppendingPathComponent:(__bridge NSString *)newUniqueIdString];
- CFRelease(newUniqueId);
- CFRelease(newUniqueIdString);
+ NSString *tmpPath = [NSString pathForTemporaryFile];
// rename the file, waiting for the rename to finish before async deletion
dispatch_sync(_renameQueue, ^{
View
22 Core/Source/NSString+DTPaths.h
@@ -34,4 +34,26 @@
*/
+ (NSString *)documentsPath;
+/**-------------------------------------------------------------------------------------
+ @name Getting Temporary Paths
+ ---------------------------------------------------------------------------------------
+ */
+
+/** Determines the path for temporary files in the current application's sandbox.
+
+ The return value is cached on the first call. This value is different in Simulator than on the actual device. In Simulator you get a reference to /tmp wheras on iOS devices it is a special folder inside the application folder.
+
+ @return The path to the app's folder for temporary files.
+ */
++ (NSString *)temporaryPath;
+
+
+/** Creates a unique filename that can be used for one temporary file or folder.
+
+ The returned string is different on every call. It is created by combining the result from temporaryPath with a unique UUID.
+
+ @return The generated temporary path.
+ */
++ (NSString *)pathForTemporaryFile;
+
@end
View
27 Core/Source/NSString+DTPaths.m
@@ -13,6 +13,8 @@
@implementation NSString (DTPaths)
+#pragma mark Standard Paths
+
+ (NSString *)cachesPath
{
static dispatch_once_t onceToken;
@@ -37,4 +39,29 @@ + (NSString *)documentsPath
return cachedPath;
}
+#pragma mark Temporary Paths
+
++ (NSString *)temporaryPath
+{
+ static dispatch_once_t onceToken;
+ static NSString *cachedPath;
+
+ dispatch_once(&onceToken, ^{
+ cachedPath = NSTemporaryDirectory();
+ });
+
+ return cachedPath;
+}
+
++ (NSString *)pathForTemporaryFile
+{
+ CFUUIDRef newUniqueId = CFUUIDCreate(kCFAllocatorDefault);
+ CFStringRef newUniqueIdString = CFUUIDCreateString(kCFAllocatorDefault, newUniqueId);
+ NSString *tmpPath = [NSTemporaryDirectory() stringByAppendingPathComponent:(__bridge NSString *)newUniqueIdString];
+ CFRelease(newUniqueId);
+ CFRelease(newUniqueIdString);
+
+ return tmpPath;
+}
+
@end
Please sign in to comment.
Something went wrong with that request. Please try again.