Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#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