HYRouter is the router framework that I built while I was doing one of my app with module development. It helps you decouple ViewControllers, run all your ViewControllers in a debug UITableViewController and flexibly set up the main UITabbarController.
If you use traditinal navigation methods offered by Apple, you can't decouple two modules. Each time when you navigate to the B_ViewController, you have to init an object of the B_ViewController. It means that you have to know the existence the B_ViewController Class. When the B_ViewController is from a different module, decoupling modules becomes very tough.
- Navigate through the ViewController Identifier
- Pass data between ViewControllers easily
- Support ViewController with storyboard or without storyboard
- Configure the main UITabBarController with a dictionary
- Setup entries for all ViewController in the dubug mode
You can install HYRouter via CocoaPods by adding it to your Podfile
:
use_frameworks!
source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '8.0'
pod 'HYRouter'
And run pod install
.
import HYRouter
class MyViewController:UIViewController, RouterController {
var params: [String : Any]?
}
All data from previous ViewController will be here
let param = RouterParams()
param["videoUrl"] = "https://video.com/id=123"
navigate(controllerName: String, params:RouterParams,isPresent: Bool)
- controllerName: When the next ViewController use storyboard, the controllerName is the stroyboard identifier. When doesn't use storyboard, the controllerName is the ViewController class name
- params: data is configured in a dictionary structure
- isPresent: True for presentViewController, false for pushViewController
import HYRouter
class MyViewController:UIViewController, RouterController {
var params: [String : Any]? {
didSet {
guard let params = params else { return }
if params.keys.contains("videoUrl")
{ self.urlString = params["videoUrl"] as? String }
}
}
}
AppDelegate.swift
import HYRouter
let vcs = ["Record","ActityHisController","History"]
window?.rootViewController = DebugLaucher.tableController(controllers: vcs)
AppDelegate.swift
import HYRouter
let vcs = ["Record","ActityHisController","History"]
window?.rootViewController = DebugLaucher.tabController(controllers: vcs)