Latest 0.1.1
Homepage https://github.com/igrekde/UIViewController-Routing
License MIT
Platforms ios 7.0
Authors

UIViewController+Routing is a handy category, which helps with implementing a better navigation in iOS applications using Routers.

It does the following things at the moment:

  • Holds an abstract router,
  • Swizzles -prepareForSegue: method, forwarding it to the router.
  • Provides the -performSegueWithBlock: method, which helps to get rid of fat -prepareForSegue: method.

Installation

You can install this category in two ways:

  • Recommended: Install the Cocoapods gem, create Podfile and add the following line:

    pod 'UIViewController+Routing', '~> 0.1'
  • Copy two files, UIViewController+Routing.h and UIViewController+Routing.m to your project.

Usage

  1. Create a new class, Router, which inherits from NSObject. Make this class conform to YDRouter protocol:

    @interface YDRouterBase : NSObject <YDRouter>
    
    @end
  2. Implement any number of navigation methods with the following implementation:

    - (void)showDetailViewControllerFromSourceViewController:(UIViewController *)sourceViewController withDictionary:(NSDictionary *)detailDictionary {
    YDSeguePreparationBlock preparationBlock =  ^void(UIStoryboardSegue *segue) {
        YDDetailViewController *destinationViewController = segue.destinationViewController;
        destinationViewController.detailDictionary = detailDictionary;
        destinationViewController.router = self;
    };
    
    [sourceViewController performSegueWithIdentifier:YDDetailSegueIdentifier sender:self preparationBlock:preparationBlock];
    }
  3. Implement the – prepareForSegue: method in your router:

    - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    UIViewController *sourceViewController = segue.sourceViewController;
    YDSeguePreparationBlock block = [sourceViewController preparationBlockForSegue:segue];
    
    if (block) {
        block(segue);
    }
    }
  4. From now on, every time you called for -performSegue:withIdentifier: method, use the appropriate method of your router.

Example

The project now contains a nice demo project, which shows some aspects of using this category and Routers objects. Remember to run pod install before building the demo app. Feel free to ask your questions in the Issues.

Additional Info

Here you can read about using this category for a simple test case (in Russian). And check this [project] for an example of usage this concept in a more realistic app.

Author

Egor Tolstoy@igrekde.

License

UIViewController+Routing is available under the MIT license. See the LICENSE file for more info.

Latest podspec

{
    "name": "UIViewController+Routing",
    "version": "0.1.1",
    "summary": "UIViewController+Routing is a handy category, which helps with implementing a better navigation in iOS applications using Routers.",
    "description": "                   **UIViewController+Routing** is a handy category, which helps with implementing a better navigation in iOS applications using *Routers*.nn                   It does the following things at the moment:n                   - Holds an abstract router,n                   - Swizzles *-prepareForSegue:* method, forwarding it to the router,n                   - Provides the *-performSegueWithBlock:* method, which helps to get rid of fat *-prepareForSegue:* method.n",
    "homepage": "https://github.com/igrekde/UIViewController-Routing",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "igrekde": "[email protected]"
    },
    "social_media_url": "http://twitter.com/igrekde",
    "platforms": {
        "ios": "7.0"
    },
    "source": {
        "git": "https://github.com/igrekde/UIViewController-Routing.git",
        "tag": "0.1.1"
    },
    "source_files": [
        "Classes",
        "Classes/**/*.{h,m}"
    ],
    "exclude_files": "Classes/Exclude"
}

Pin It on Pinterest

Share This