PRRouter 0.2

PRRouter 0.2

TestsTested
LangLanguage Obj-CObjective C
License MIT
ReleasedLast Release May 2016

Maintained by Elethom Hunter.



URL router framework for iOS

Why use a router?

Here's a typical way of navigating through view controllers:

#import "MyViewController.h"

...

MyViewController *controller = [[MyViewController alloc] init];
controller.someProperty = someProperty;
controller.someOtherProperty = someOtherProperty
[self.navigationController pushViewController:controller
                                     animated:YES];

Here's the same job did with a router.

[[PRRouter defaultRouter] openURL:myModel.url
         withNavigationController:self.navigationController];

Benefits of using a router:

  • less coupling & more flexible
  • navigation logic can be controlled by the server side
  • better backward compatibility by falling back to web view

Installation

Getting Started

Map a path to a view controller class

@implementation PRUserViewController

...

#pragma mark - Life cycle

+ (void)load
{
    [[PRRouter defaultRouter] mapPath:@"/user/:user_id"
                    toControllerClass:self];
}

...

@end

Implement -initWithParams:query:fragment:

@implementation PRUserViewController

...

- (instancetype)initWithParams:(NSDictionary *)params
                         query:(NSDictionary *)query
                      fragment:(NSString *)fragment
{
    self = [super initWithParams:params
                           query:query
                        fragment:fragment];
    if (self) {
        // Initialize your view controller
    }
    return self;
}

...

@end

Use URL to navigate to a view conroller

@implementation PRContactsViewController

...

#pragma mark - UITableViewDelegate

- (void)tableView:(UITableView *)tableView
    didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    PRContact *contact = self.viewModel.objects[indexPath.row];
    [[PRRouter defaultRouter] openURL:contact.url
             withNavigationController:self.navigationController];
}

...

@end

Full API Reference

See Documentation.

LICENSE

This project is released under the terms and conditions of the MIT license. See LICENSE for details.

Contact

This project is designed and developed by Elethom Hunter. You can reach me via:

Be Social

Donate

You can support me by:

:-)