Skip to content
This repository has been archived by the owner on Aug 8, 2018. It is now read-only.

godaddy/GDRouting

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

25 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

GDRouting

GDRouting is a framework for using private CocoaPod repositories to modularizing a large application into sub-applications. The open source repo JLRoutes is used create x-callback-urls to glue all the sub-apps together accessible though a menu system or with string keys exposed in each sub-app.

This repo buids upon concepts taken from the blog post Using CocoaPods to Modularize a Big iOS App by Anthony Roldan of HubSpot.

GDMenuItem

GDMenuItem hold properties that determine what shows up in the menu table view, these being title and iconImageName. It also has properies of displayOrder so that you can order menu items in a sub-app and sectionTitle if you want a section header to appear before the menu item.

GDMenuItem *menuItem = [[GDMenuItem alloc] initWithTitle:MenuItemTitle andDisplayOrder:0];
menuItem.sectionTitle = SectionTitle;

GDRoute

GDRoute stores information about the urlString and the routing block to be called when the route is selected
GDRoute *route = [GDRoute routeWithURLString:[NSString stringWithFormat:@"/%@", ViewControllerIdentifier] andAction: ^BOOL (id  routingDelegate, NSString *urlString, NSDictionary *parameters) {
	[routingDelegate pushRoutedViewController:[UIStoryboard instantiateViewControllerWithIdentifier:ViewControllerIdentifier andStoryboardName:StoryboardName] animated:YES parameters:nil];
	    return YES;
	}];
 

GDBaseApp

All sub-applications should have at least one class that implements this protocol. It is used to get menu items and routes used in the sub-app.

Here is what the implementation of the ManateeApp looks like:

@implementation ManateeApp

static NSString *const StoryboardName = @"Main";
static NSString *const ViewControllerIdentifier = @"ManateeViewController";
static NSString *const MenuItemTitle = @"MANATEES";

+ (UINavigationController *)baseNavigationController
{
	return [[UINavigationController alloc] initWithRootViewController:[UIStoryboard instantiateViewControllerWithIdentifier:ViewControllerIdentifier andStoryboardName:StoryboardName]];
}

+ (NSArray *)menuItems
{
	GDMenuItem *menuItem = [[GDMenuItem alloc] initWithTitle:MenuItemTitle andIconImageName:nil];
	return @[menuItem];
}

+ (NSDictionary *)routesToRegister
{
	GDRoute *route = [GDRoute routeWithURLString:[NSString stringWithFormat:@"/%@", ViewControllerIdentifier] andAction: ^BOOL (id  routingDelegate, NSString *urlString, NSDictionary *parameters) {
	    [routingDelegate popRoutedViewControllerToRootViewController:YES parameters:nil];
	    return YES;
	}];

    NSDictionary *routeDictionary = @{ViewControllerIdentifier : route};
	return routeDictionary;
}

GDUsableApp

A GDUsableApp is a representation of an sub-app that is configured for use in your main application. It has 2 properties, displayOrder which is used to determine what order menu items from the app show up in menu and appName which matches the name of the sub-app class that you want to import.

Usage:

GDUsableApp *manateeApp = [[GDUsableApp alloc] init];
manateeApp.displayOrder = 0;
manateeApp.appName = @"ManateeApp";

GDAppConfiguration

GDAppConfiguration is an archivable object used to store configuration information about the app.

    GDAppConfiguration *appConfiguration = [[GDAppConfiguration alloc] init];
    appConfiguration.usableAppArray = @[manateeApp];
    [appConfiguration archiveObject];

GDAppManager

GDAppManager provides functionality to get all the available GDMenuItems and GDRoutes configured in an application using an array of GDUsableApps. It is also used to set up all your routes.
    GDAppManager *appManager = [[GDAppManager alloc] initWithUsableAppArray:appConfiguration.usableAppArray];
    [appManager registerRoutesForAppsWithRoutingDelegate:self];