foundationkit / FoundationKit

Everything that really should be in Foundation, but isn't. Future-proof with ARC
Other
80 stars 9 forks source link

Shorthands for accessing application support and resources directory #28

Closed MSch closed 13 years ago

MSch commented 13 years ago

I'd like to add those methods somewhere.

+ (NSString *)applicationName {
    return [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleName"];
}

+ (NSString *)appSupportPath {
    return [[self appSupportURL] path];
}

+ (NSURL *)appSupportURL {
    NSFileManager *fileManager = [NSFileManager defaultManager];
    NSURL *libraryURL = [[fileManager URLsForDirectory:NSApplicationSupportDirectory inDomains:NSUserDomainMask] lastObject];
    return [libraryURL URLByAppendingPathComponent:[self applicationName]];
}

+ (NSURL *)URLForAppSupportPath:(NSString *)path {
    return [[self appSupportURL] URLByAppendingPathComponent:path];
}

+ (NSString *)pathForAppSupportPath:(NSString *)path {
    return [NSString stringWithFormat:@"%@/%@", [self appSupportPath], path];
}

+ (NSString *)resourcesPath {
    return [[NSBundle mainBundle] resourcePath];
}

+ (NSURL *)resourcesURL {
    return [[NSBundle mainBundle] resourceURL];
}

+ (NSString *)pathForResource:(NSString *)path {
    return [NSString stringWithFormat:@"%@/%@", [self resourcesPath], path];
}

+ (NSURL *)URLForResource:(NSString *)path {
    return [[self resourcesURL] URLByAppendingPathComponent:path];
}

Thoughts?

myell0w commented 13 years ago

I don't know what the appSupportPath etc. is for, but I guess self in this case means the UI/NSAplication (or the delegate), so a singleton?

I would suggest making FK - Functions out of it (also FKDocumentsDirectory(), FKLibraryDirectory() etc.)

Am 22.07.2011 um 12:39 schrieb MSch:

I'd like to add those methods somewhere.

+ (NSString *)applicationName {
   return [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleName"];
}

+ (NSString *)appSupportPath {
   return [[self appSupportURL] path];
}

+ (NSURL *)appSupportURL {
   NSFileManager *fileManager = [NSFileManager defaultManager];
   NSURL *libraryURL = [[fileManager URLsForDirectory:NSApplicationSupportDirectory inDomains:NSUserDomainMask] lastObject];
   return [libraryURL URLByAppendingPathComponent:[self applicationName]];
}

+ (NSURL *)URLForAppSupportPath:(NSString *)path {
   return [[self appSupportURL] URLByAppendingPathComponent:path];
}

+ (NSString *)pathForAppSupportPath:(NSString *)path {
   return [NSString stringWithFormat:@"%@/%@", [self appSupportPath], path];
}

+ (NSString *)resourcesPath {
   return [[NSBundle mainBundle] resourcePath];
}

+ (NSURL *)resourcesURL {
   return [[NSBundle mainBundle] resourceURL];
}

+ (NSString *)pathForResource:(NSString *)path {
   return [NSString stringWithFormat:@"%@/%@", [self resourcesPath], path];
}

+ (NSURL *)URLForResource:(NSString *)path {
   return [[self resourcesURL] URLByAppendingPathComponent:path];
}

Thoughts?

Reply to this email directly or view it on GitHub: https://github.com/foundationkit/FoundationKit/issues/28

MSch commented 13 years ago

Oh, there's no 'Application Support' directory on iOS? Need to move that to MacKit then.

Basically these methods return paths/URLs to the Resources/Application Support dir, respective paths/URLs to files/folders inside those dirs.

I personally would prefer [FKSomething resourcesPath] but I'm fine with FKResourcesPath()

eaigner commented 13 years ago

I think the methods should be in a category on NSBundle, since NSBundle (-mainBundle) usually handles the paths/resources/etc. and we don't need to differentiate between NS and UI(as in e.g. UIApplication).

myell0w commented 13 years ago

Functions for this task would be the same style as the standard function NSHomeDirectory()

eaigner commented 13 years ago

PS: I wouldn't mix app and application in method names. Keep it consistent using application only?