ZIKRouter
An interface-oriented router for discovering modules and injecting dependencies with protocol.
The view router can perform all navigation types in UIKit through one method.
The service router can discover and prepare corresponding module with it's protocol.
Features
- [x] Swift, Objective-C and mixed development Support
- [x] Routing for UIViewController, UIView and any classes
- [x] Dependency injection
- [x] Locate view and service with it's protocol
- [x] Prepare the module with it's protocol when performing route, rather than passing a parameter dictionary
- [x] Use different protocols inside module and module's caller to get the same module, then the caller won't couple with any protocol
- [x] Declare routable protocol. There're compile-time checking and runtime checking to make safe routing
- [x] Declare a specific router with generic parameters
- [x] Decouple modules and add compatible interfaces with adapter
- [x] Encapsulate navigation methods in UIKit (push, present modally, present as popover, segue, show, showDetail, addChildViewController, addSubview) and custom transitions into one method
- [x] Remove a UIviewController/UIView or unload a module through one method, without using pop、dismiss、removeFromParentViewController、removeFromSuperview in different situation. Router can choose the proper method
- [x] Support storyboard. UIViewController and UIView from a segue can auto create it's registered router
- [x] Error checking for UIKit view transition
- [x] AOP for view transition
- [ ] Support Mac OS and tv OS
- [ ] Register router manually after launch, not just automatically registering all routers
- [ ] Add route for module with block, not just router subclasses
Sample
View Router
Demo view controller and protocol:
Objective-C Sample
Transition directly
Transition to editor view directly:
Objective-C Sample
You can change transition type with routeType
:
Transition and Prepare
Transition to editor view, and prepare it before transition:
Objective-C Sample
Remove
You can remove the view by removeRoute
, without using pop / dismiss / removeFromParentViewController / removeFromSuperview:
Objective-C Sample
Service Router
Get a module and use:
Objective-C Sample
Demo and Practice
ZIKRouter is designed for VIPER architecture at first. But you can also use it in MVC or anywhere.
The demo (ZIKRouterDemo) in this repository shows how to use ZIKRouter to perform each route type.
If you want to see how it works in a VIPER architecture app, go to ZIKViper.
Installation
Cocoapods
For Objective-C project:
pod 'ZIKRouter', '0.13.0'
For Swift project:
pod 'ZRouter', '0.9.0'
How to use
Quick start to use ZIKRouter.
1.Create Router
Create router subclass for your module:
Objective-C Sample
Read the documentation for more details and more methods to override.