Latest 0.2
Homepage https://github.com/Elethom/PRRouter
License MIT
Platforms ios , requires ARC
Authors

PRRouter CocoaPods compatible Carthage compatible Build Status Language License

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

With Carthage

Carthage can be installed with Homebrew:

$ brew update
$ brew install carthage

Add PRRouter to your Cartfile:

github "Elethom/PRRouter"

Run carthage to build the framework and add the built PRRouter.framework to your Xcode project.

With CocoaPods

CocoaPods can be installed with RubyGems:

$ gem install cocoapods

Add PRRouter to your Podfile:

pod 'PRRouter'

Run pod install to install the framework.

Getting Started

Map a path to a view controller class

@implementation PRUserViewController

...

#pragma mark - Life cycle

+ (void)load
{
    [self pr_mapToPath:@"/user/:user_id"];
}

...

@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

Tweet
Twitter

Donate

You can support me by:

:-)

Latest podspec

{
    "name": "PRRouter",
    "version": "0.2",
    "summary": "URL router framework for iOS",
    "homepage": "https://github.com/Elethom/PRRouter",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "Elethom Hunter": "[email protected]"
    },
    "social_media_url": "http://twitter.com/ElethomHunter",
    "platforms": {
        "ios": null
    },
    "source": {
        "git": "https://github.com/Elethom/PRRouter.git",
        "tag": "0.2"
    },
    "source_files": "Sources/**/*.{h,m}",
    "public_header_files": [
        "Sources/Classes/PRRouter.h",
        "Sources/Categories/UIViewController+PRRouter.h"
    ],
    "requires_arc": true
}

Pin It on Pinterest

Share This