Skip to content

Instantly share code, notes, and snippets.

@craigmarvelley
Last active March 10, 2016 15:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save craigmarvelley/6a5805fcec4e79db2b0f to your computer and use it in GitHub Desktop.
Save craigmarvelley/6a5805fcec4e79db2b0f to your computer and use it in GitHub Desktop.
#import "AppDelegate.h"
@interface AppDelegate ()
@property (strong, nonatomic) NSManagedObjectContext *managedObjectContext;
@property (strong, nonatomic) GCDWebServer *webServer;
@end
@implementation AppDelegate
#pragma mark - UIApplicationDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[self bootstrapApplication];
return YES;
}
- (void)bootstrapApplication {
[self setUpHttpServer];
if (![self userIsAuthenticated]) {
[self showLoginView];
} else {
[self setUpDatabase:^{
[self showHomeView];
}];
}
}
- (BOOL)userIsAuthenticated {
// Query keychain for authentication data
return YES;
}
- (void)showLogInView {
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"LogIn" bundle:nil];
LogInViewController *logInController = (LogInViewController *)[storyboard instantiateInitialViewController];
// Set up more dependencies, store them on the delegate, and inject them
[self changeRootViewController:logInController];
}
- (void)showHomeView {
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Home" bundle:nil];
UISplitViewController *homeController = (UISplitViewController *)[storyboard instantiateInitialViewController];
// Set up EVEN MORE dependencies, store them on the delegate, and inject them
[self changeRootViewController:homeController];
}
- (void)changeRootViewController:(UIViewController *)viewController {
self.window.rootViewController = viewController;
}
- (void)authenticationStatusDidChange:(NSNotification *)notification {
if ([self userIsAuthenticated]) {
[self showHomeView];
} else {
[self showLoginView];
}
}
#pragma mark -
- (void)setUpWebServer {
if (!_webServer) {
_webServer = [[GCDWebServer alloc] init];
[_webServer startWithPort:0 bonjourName:nil];
}
}
#pragma mark -
- (void)setUpDatabase:(void (^)(void))callback {
// Create persistent store coordinator, managed object context, etc. in another thread then execute callback block
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment