Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion ABRouter/ABRouter.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@

#import <Foundation/Foundation.h>

@class ABViewController;

@protocol Routable <NSObject>
@property(nonatomic,retain) NSString *apiPath;

Expand All @@ -36,6 +38,8 @@
- (void)match:(NSString*)pattern to:(Class)aClass;
- (void)display:(id)obj withNavigationController:(UINavigationController*)navController;
- (void)navigateTo:(NSString*)route withNavigationController:(UINavigationController*)navController;
- (void)navigateTo:(NSString*)route withNavigationController:(UINavigationController*)navController andQuery:(NSDictionary*)query;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please change the method signature to (and change query):

- (void)navigateTo:(NSString*)route navigationController:(UINavigationController*)navController parameters:(NSDictionary*)parameters;

- (void)modallyPresent:(NSString*)route from:(UIViewController*)viewController;
- (UIViewController<Routable> *)match:(NSString*)route;
- (void)modallyPresent:(NSString*)route from:(UIViewController*)viewController withQuery:(NSDictionary*)query;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please remove the word with and perhaps change query to something more indicative of what it is and does. Perhaps:

+- (void)modallyPresent:(NSString*)route from:(UIViewController*)viewController parameters:(NSDictionary*)parameters;

- (ABViewController<Routable> *)match:(NSString*)route;
@end
32 changes: 25 additions & 7 deletions ABRouter/ABRouter.m
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,11 @@

#import "ABRouter.h"
#import "SOCKit.h"

#import "ABViewController.h"
#define kPatternKey @"PatternKey"
#define kViewControllerKey @"ViewControllerKey"


static ABRouter *_sharedRouter = nil;

@implementation ABRouter
Expand Down Expand Up @@ -69,28 +70,44 @@ - (void)match:(NSString*)pattern to:(Class)aClass
[routePatterns addObject:[NSDictionary dictionaryWithObjectsAndKeys:[SOCPattern patternWithString:pattern], kPatternKey, aClass, kViewControllerKey, nil]];
}

- (void)modallyPresent:(NSString*)route from:(UIViewController*)viewController
- (void)modallyPresent:(NSString*)route from:(ABViewController*)viewController
{
UIViewController<Routable> * pushMe = [self match:route];
ABViewController<Routable> * pushMe = [self match:route];
pushMe.apiPath = route;
UINavigationController *nav = [[[UINavigationController alloc] initWithRootViewController:pushMe] autorelease];
[viewController presentModalViewController:nav animated:YES];
}

- (void)modallyPresent:(NSString*)route from:(UIViewController*)viewController withQuery:(NSDictionary*)query
{
ABViewController<Routable> * pushMe = [self match:route];
pushMe.apiPath = route;
pushMe.query = query;
UINavigationController *nav = [[[UINavigationController alloc] initWithRootViewController:pushMe] autorelease];
[viewController presentModalViewController:nav animated:YES];
}

- (void)display:(id)obj withNavigationController:(UINavigationController*)navController
{
UIViewController<Routable> * pushMe = [self match:[obj path]];
ABViewController<Routable> * pushMe = [self match:[obj path]];
pushMe.entity = obj;
[navController pushViewController:pushMe animated:YES];
}

- (void)navigateTo:(NSString*)route withNavigationController:(UINavigationController*)navController
{
UIViewController<Routable> * pushMe = [self match:route];
ABViewController<Routable> * pushMe = [self match:route];
[navController pushViewController:pushMe animated:YES];
}

- (void)navigateTo:(NSString*)route withNavigationController:(UINavigationController*)navController andQuery:(NSDictionary*)query
{
ABViewController<Routable> * pushMe = [self match:route];
pushMe.query = query;
[navController pushViewController:pushMe animated:YES];
}

- (UIViewController<Routable> *)match:(NSString*)route
- (ABViewController<Routable> *)match:(NSString*)route
{
NSArray *pathInfo = [route componentsSeparatedByString:@"?"];
route = [pathInfo objectAtIndex:0];
Expand Down Expand Up @@ -119,7 +136,8 @@ - (void)navigateTo:(NSString*)route withNavigationController:(UINavigationContro
SOCPattern *pattern = [match objectForKey:kPatternKey];
Class class = [match objectForKey:kViewControllerKey];

UIViewController<Routable> * pushMe = [[[class alloc] init] autorelease];

ABViewController<Routable> * pushMe = [[[class alloc] init] autorelease];
pushMe.apiPath = route;

if ([pushMe respondsToSelector:@selector(setParameters:)])
Expand Down
16 changes: 16 additions & 0 deletions ABRouter/ABViewController.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//
// ABViewController.h
// Example
//
// Created by Pierre on 25/11/12.
// Copyright (c) 2012 Structlab LLC. All rights reserved.
//

#import <UIKit/UIKit.h>

@interface ABViewController : UIViewController <Routable>

@property (nonatomic, retain) NSDictionary *query;
@property (nonatomic, retain) NSString *apiPath;

@end
45 changes: 45 additions & 0 deletions ABRouter/ABViewController.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
//
// ABViewController.m
// Example
//
// Created by Pierre on 25/11/12.
// Copyright (c) 2012 Structlab LLC. All rights reserved.
//

#import "ABViewController.h"

@interface ABViewController ()

@end

@implementation ABViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}

- (void)dealloc
{
self.query = nil;
self.apiPath = nil;
[super dealloc];
}

- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
}

- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}

@end
18 changes: 18 additions & 0 deletions Example.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
objects = {

/* Begin PBXBuildFile section */
8FED60E216629B370011D051 /* ABViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 8FED60E116629B370011D051 /* ABViewController.m */; };
8FED60E716629DB30011D051 /* ObjectViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 8FED60E516629DB30011D051 /* ObjectViewController.m */; };
8FED60E816629DB30011D051 /* ObjectViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 8FED60E616629DB30011D051 /* ObjectViewController.xib */; };
9305BF7E1414568D0052A06F /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 9305BF7D1414568D0052A06F /* UIKit.framework */; };
9305BF801414568D0052A06F /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 9305BF7F1414568D0052A06F /* Foundation.framework */; };
9305BF821414568D0052A06F /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 9305BF811414568D0052A06F /* CoreGraphics.framework */; };
Expand All @@ -27,6 +30,11 @@
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
8FED60E016629B370011D051 /* ABViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ABViewController.h; sourceTree = "<group>"; };
8FED60E116629B370011D051 /* ABViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ABViewController.m; sourceTree = "<group>"; };
8FED60E416629DB30011D051 /* ObjectViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ObjectViewController.h; sourceTree = "<group>"; };
8FED60E516629DB30011D051 /* ObjectViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ObjectViewController.m; sourceTree = "<group>"; };
8FED60E616629DB30011D051 /* ObjectViewController.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = ObjectViewController.xib; sourceTree = "<group>"; };
9305BF791414568D0052A06F /* Example.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Example.app; sourceTree = BUILT_PRODUCTS_DIR; };
9305BF7D1414568D0052A06F /* UIKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = System/Library/Frameworks/UIKit.framework; sourceTree = SDKROOT; };
9305BF7F1414568D0052A06F /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; };
Expand Down Expand Up @@ -127,6 +135,8 @@
children = (
9305BF9C141456A70052A06F /* ABRouter.h */,
9305BF9D141456A70052A06F /* ABRouter.m */,
8FED60E016629B370011D051 /* ABViewController.h */,
8FED60E116629B370011D051 /* ABViewController.m */,
);
path = ABRouter;
sourceTree = "<group>";
Expand Down Expand Up @@ -155,6 +165,9 @@
9305BFB4141459690052A06F /* AlbumListViewController.h */,
9305BFB5141459690052A06F /* AlbumListViewController.m */,
9305BFB6141459690052A06F /* AlbumListViewController.xib */,
8FED60E416629DB30011D051 /* ObjectViewController.h */,
8FED60E516629DB30011D051 /* ObjectViewController.m */,
8FED60E616629DB30011D051 /* ObjectViewController.xib */,
);
path = "View Controllers";
sourceTree = "<group>";
Expand Down Expand Up @@ -215,6 +228,7 @@
9305BFAE1414594C0052A06F /* PhotoListViewController.xib in Resources */,
9305BFB3141459580052A06F /* PhotoViewController.xib in Resources */,
9305BFB8141459690052A06F /* AlbumListViewController.xib in Resources */,
8FED60E816629DB30011D051 /* ObjectViewController.xib in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand All @@ -233,6 +247,8 @@
9305BFAD1414594C0052A06F /* PhotoListViewController.m in Sources */,
9305BFB2141459580052A06F /* PhotoViewController.m in Sources */,
9305BFB7141459690052A06F /* AlbumListViewController.m in Sources */,
8FED60E216629B370011D051 /* ABViewController.m in Sources */,
8FED60E716629DB30011D051 /* ObjectViewController.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -306,6 +322,7 @@
buildSettings = {
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = "Example/Example-Prefix.pch";
GCC_VERSION = "";
INFOPLIST_FILE = "Example/Example-Info.plist";
PRODUCT_NAME = "$(TARGET_NAME)";
WRAPPER_EXTENSION = app;
Expand All @@ -317,6 +334,7 @@
buildSettings = {
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = "Example/Example-Prefix.pch";
GCC_VERSION = "";
INFOPLIST_FILE = "Example/Example-Info.plist";
PRODUCT_NAME = "$(TARGET_NAME)";
WRAPPER_EXTENSION = app;
Expand Down
2 changes: 1 addition & 1 deletion Example/Example-Prefix.pch
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@
#import <Foundation/Foundation.h>
#endif

#import "ABRouter.h"
#import "ABRouter.h"
4 changes: 3 additions & 1 deletion Example/ExampleAppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#import "PhotoViewController.h"
#import "AlbumListViewController.h"
#import "PhotoListViewController.h"
#import "ObjectViewController.h"

@implementation ExampleAppDelegate

Expand All @@ -24,7 +25,8 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
[[ABRouter sharedRouter] match:@"/photos/:id" to:[PhotoViewController class]];
[[ABRouter sharedRouter] match:@"/albums" to:[AlbumListViewController class]];
[[ABRouter sharedRouter] match:@"/albums/:id" to:[PhotoListViewController class]];

[[ABRouter sharedRouter] match:@"/object" to:[ObjectViewController class]];

self.rootViewController = [[[RootViewController alloc] init] autorelease];
self.navigationController = [[[UINavigationController alloc] initWithRootViewController:self.rootViewController] autorelease];
[self.window addSubview:self.navigationController.view];
Expand Down
4 changes: 2 additions & 2 deletions Example/View Controllers/AlbumListViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
//

#import <UIKit/UIKit.h>
#import "ABViewController.h"

@interface AlbumListViewController : UIViewController <Routable>
@property(nonatomic,retain) NSString *apiPath;
@interface AlbumListViewController : ABViewController
@property(nonatomic,retain) IBOutlet UILabel *pathLabel;
- (IBAction)showAlbum:(id)sender;
@end
13 changes: 13 additions & 0 deletions Example/View Controllers/ObjectViewController.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//
// ObjectViewController.h
// Example
//
// Created by Pierre on 25/11/12.
// Copyright (c) 2012 Structlab LLC. All rights reserved.
//

#import "ABViewController.h"

@interface ObjectViewController : ABViewController
@property (nonatomic,retain) IBOutlet UILabel *dateLabel;
@end
43 changes: 43 additions & 0 deletions Example/View Controllers/ObjectViewController.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
//
// ObjectViewController.m
// Example
//
// Created by Pierre on 25/11/12.
// Copyright (c) 2012 Structlab LLC. All rights reserved.
//

#import "ObjectViewController.h"

@interface ObjectViewController ()

@end

@implementation ObjectViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {

// Custom initialization
}
return self;
}


- (void)viewDidLoad
{
[super viewDidLoad];

NSDate *date = [self.query objectForKey:@"date"];
[self.dateLabel setText:[NSString stringWithFormat:@"%@",date]];
// Do any additional setup after loading the view from its nib.
}

- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}

@end
Loading