Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

NSFileManager+DirectoryLocations

  • Loading branch information...
commit 006cce7f1726d88a01feb29f712c742af1644257 1 parent 5086592
@mxcl authored
View
2  NSFileManager+DirectoryLocations.h
@@ -31,6 +31,8 @@
inDomain:(NSSearchPathDomainMask)domainMask
appendPathComponent:(NSString *)appendComponent
error:(NSError **)errorOut;
+
- (NSString *)applicationSupportDirectory;
+- (NSString *)cacheDirectory;
@end
View
49 NSFileManager+DirectoryLocations.m
@@ -66,17 +66,12 @@ - (NSString *)findOrCreateDirectory:(NSSearchPathDirectory)searchPathDirectory
if (errorOut)
{
NSDictionary *userInfo =
- [NSDictionary dictionaryWithObjectsAndKeys:
- NSLocalizedStringFromTable(
+ @{NSLocalizedDescriptionKey: NSLocalizedStringFromTable(
@"No path found for directory in domain.",
@"Errors",
nil),
- NSLocalizedDescriptionKey,
- [NSNumber numberWithInteger:searchPathDirectory],
- @"NSSearchPathDirectory",
- [NSNumber numberWithInteger:domainMask],
- @"NSSearchPathDomainMask",
- nil];
+ @"NSSearchPathDirectory": @(searchPathDirectory),
+ @"NSSearchPathDomainMask": @(domainMask)};
*errorOut =
[NSError
errorWithDomain:DirectoryLocationDomain
@@ -89,7 +84,7 @@ - (NSString *)findOrCreateDirectory:(NSSearchPathDirectory)searchPathDirectory
//
// Normally only need the first path returned
//
- NSString *resolvedPath = [paths objectAtIndex:0];
+ NSString *resolvedPath = paths[0];
//
// Append the extra path component
@@ -128,28 +123,20 @@ - (NSString *)findOrCreateDirectory:(NSSearchPathDirectory)searchPathDirectory
return resolvedPath;
}
-//
-// applicationSupportDirectory
-//
-// Returns the path to the applicationSupportDirectory (creating it if it doesn't
-// exist).
-//
-- (NSString *)applicationSupportDirectory
-{
- NSString *executableName =
- [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleExecutable"];
- NSError *error;
- NSString *result =
- [self
- findOrCreateDirectory:NSApplicationSupportDirectory
- inDomain:NSUserDomainMask
- appendPathComponent:executableName
- error:&error];
- if (!result)
- {
- NSLog(@"Unable to find or create application support directory:\n%@", error);
- }
- return result;
+#define MBExecutableName [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleExecutable"]
+
+- (NSString *)applicationSupportDirectory {
+ return [self findOrCreateDirectory:NSApplicationSupportDirectory
+ inDomain:NSUserDomainMask
+ appendPathComponent:MBExecutableName
+ error:nil];
+}
+
+- (NSString *)cacheDirectory {
+ return [self findOrCreateDirectory:NSCachesDirectory
+ inDomain:NSUserDomainMask
+ appendPathComponent:MBExecutableName
+ error:nil];
}
@end
Please sign in to comment.
Something went wrong with that request. Please try again.