Closed MSch closed 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
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()
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
).
Functions for this task would be the same style as the standard function NSHomeDirectory()
PS: I wouldn't mix app
and application
in method names. Keep it consistent using application
only?
I'd like to add those methods somewhere.
Thoughts?