Giter VIP home page Giter VIP logo

hyrouter's Introduction

Language: Swift Platform: iOS 8+ cocoapods compatible License: MIT Release version

Introduction

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.

Feathers

  • 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

Installation

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.

Usage

Router

1 - Implement the RouterController protocol

import HYRouter

class MyViewController:UIViewController, RouterController {
    var params: [String : Any]?
}

All data from previous ViewController will be here

2 - Prepare the data needed to pass

let param = RouterParams()
param["videoUrl"] = "https://video.com/id=123"

3 - Call Navigate method

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

4 - Receive the data

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 }
          }
    }
}

DebugViewController

AppDelegate.swift
import HYRouter

let vcs = ["Record","ActityHisController","History"]
window?.rootViewController = DebugLaucher.tableController(controllers: vcs)

Main UITabBarController

AppDelegate.swift
import HYRouter

let vcs = ["Record","ActityHisController","History"]
window?.rootViewController = DebugLaucher.tabController(controllers: vcs)

hyrouter's People

Contributors

cranberryyam avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

rk905

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.