Permalink
Browse files

Extracted homeDirectory method

  • Loading branch information...
0xced committed Jan 3, 2012
1 parent 9c629c2 commit 06dc591b9e71dbae2a5e2197bc515ff2a66edc70
Showing with 9 additions and 4 deletions.
  1. +1 −0 Classes/AppDelegate.h
  2. +8 −4 Classes/AppDelegate.m
View
@@ -17,6 +17,7 @@
@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) IBOutlet UITabBarController *tabBarController;
+- (NSString *) homeDirectory;
- (NSString *) saveDirectory:(NSString *)subDirectory;
@end
View
@@ -24,15 +24,19 @@ - (void) applicationDidFinishLaunching:(UIApplication *)application
[self.window addSubview:self.tabBarController.view];
}
+- (NSString *) homeDirectory
+{
+ NSString *logname = [NSString stringWithCString:getenv("LOGNAME") encoding:NSUTF8StringEncoding];
+ struct passwd *pw = getpwnam([logname UTF8String]);
+ return pw ? [NSString stringWithCString:pw->pw_dir encoding:NSUTF8StringEncoding] : [@"/Users" stringByAppendingPathComponent:logname];
+}
+
- (NSString *) saveDirectory:(NSString *)subDirectory
{
NSString *saveDirectory = nil;
#if TARGET_IPHONE_SIMULATOR
- NSString *logname = [NSString stringWithCString:getenv("LOGNAME") encoding:NSUTF8StringEncoding];
- struct passwd *pw = getpwnam([logname UTF8String]);
- NSString *home = pw ? [NSString stringWithCString:pw->pw_dir encoding:NSUTF8StringEncoding] : [@"/Users" stringByAppendingPathComponent:logname];
- saveDirectory = [NSString stringWithFormat:@"%@/Desktop/%@ %@ artwork", home, [UIDevice currentDevice].model, [UIDevice currentDevice].systemVersion];
+ saveDirectory = [NSString stringWithFormat:@"%@/Desktop/%@ %@ artwork", [self homeDirectory], [UIDevice currentDevice].model, [UIDevice currentDevice].systemVersion];
#else
saveDirectory = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];
#endif

0 comments on commit 06dc591

Please sign in to comment.