Giter Site home page Giter Site logo

urlnavigatorext's Introduction

URLNavigatorExt

CI Status Version License Platform

Example

To run the example project, clone the repo, and run pod install && sourcery from the Example directory first.

Dependencies

Installation

URLNavigatorExt is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod 'URLNavigatorExt'

Usage

  • install sourcery

    brew install sourcery

  • touch .sourcery.yml in ${SRCROOT} sourcery document
       sources:
           - ./${PROJECT_NAME}
       templates:
           - ./${PROJECT_NAME}/config
       output:
           ./${PROJECT_NAME}/config
  • Build Phases
sourcery
  • AppDelegate.swift
import URLNavigator
import URLNavigatorExt

let navigator = Navigator()

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
    // ....
    Router.registOuterUrl(jsonStr: Router.config, navigator: navigator)
    // ....
    return true
}
  • Viewcontroller
    • // sourcery: router: desc="这是页面描述"
    • // sourcery: router: name="这是页面名字"
    • // sourcery: router: path="这是页面的路径 eg: /mine/profile"
    • // sourcery: router: parameter="参数名称:参数类型(自定义类型或数组,需要实现Typeible协议):默认值"

注意:ViewController 必须实现Navigatorible协议

// sourcery: router: desc="第一个viewController"
// sourcery: router: name="home_page"
// sourcery: router: path="/home"
// sourcery: router: parameter="type:TestEnum:.a"
// sourcery: router: parameter="type1:TestEnum?:.b"
// sourcery: router: parameter="p3:String?:abc123"
// sourcery: router: parameter="p4:String?"
// sourcery: router: parameter="p5:Test2Enum?:.c"
// sourcery: router: parameter="p6:Test2Enum:.d"
// sourcery: router: parameter="p7:Int64"
// sourcery: router: parameter="blk:(()->Void)?"
class ViewController: UIViewController, Navigatorible {
    var navigator: NavigatorType
    var parameter: Router.PRHome_page?
    required init(navigator: NavigatorType, parameterible: Parameterible?) {
        self.navigator = navigator
        super.init(nibName: nil, bundle: nil)
        self.parameter = parameterible as? Router.PRHome_page
    }
    // ...
}

/// output
/*
    /// desc: 第一个viewController
    /// view: ViewController
    /// parameters:
    ///     - blk: (()->Void)? 
    ///     - p7: Int64 
    ///     - p6: Test2Enum default: .d
    ///         - c: 100
    ///         - d: 101
    ///     - p5: Test2Enum? default: .c
    ///         - c: 100
    ///         - d: 101
    ///     - p4: String? 
    ///     - p3: String? default: abc123
    ///     - type1: TestEnum? default: .b
    ///         - a: a
    ///         - b: b
    ///     - type: TestEnum default: .a
    ///         - a: a
    ///         - b: b
    public static let home_page = "\(Scheme.domain)/home"

    /// desc: 第一个viewController
    /// view: ViewController
    /// path: /home
    /// name: home_page
    public struct PRHome_page: Parameterible {
        var blk: (()->Void)?
        var p7: Int64
        var p6: Test2Enum
        var p5: Test2Enum?
        var p4: String?
        var p3: String?
        var type1: TestEnum?
        var type: TestEnum

        init(
            type: TestEnum,
            p6: Test2Enum,
            p7: Int64,
            type1: TestEnum?  = nil,
            p3: String?  = nil,
            p4: String?  = nil,
            p5: Test2Enum?  = nil,
            blk: (()->Void)?  = nil
        ) {
            self.blk = blk
            self.p7 = p7
            self.p6 = p6
            self.p5 = p5
            self.p4 = p4
            self.p3 = p3
            self.type1 = type1
            self.type = type
        }

        public static func instance(by queryItem: [String: String]) -> Self? {
            let items = queryItem.map({ ($0.key.lowercased(), $0.value) })
            let dict = [String: String](uniqueKeysWithValues: items)
            var _type: TestEnum? = .a
            if let value = dict["type"]{
                if let _enum = TestEnum(rawValue: value) {
                    _type = _enum
                }
            }
            var _p6: Test2Enum? = .d
            if let value = dict["p6"]{
                if let _value = Int(value), let _enum = Test2Enum(rawValue: _value) {
                    _p6 = _enum
                }
            }
            var _p7: Int64? = nil
            if let value = dict["p7"]{
                _p7 = Int64(value)
            }
            var type1: TestEnum? = .b
            if let value = dict["type1"]{
                if let _enum = TestEnum(rawValue: value) {
                    type1 = _enum
                }
            }
            var p3: String? = "abc123"
            if let value = dict["p3"]{
                p3 = value
            }
            var p4: String? = ""
            if let value = dict["p4"]{
                p4 = value
            }
            var p5: Test2Enum? = .c
            if let value = dict["p5"]{
                if let _value = Int(value), let _enum = Test2Enum(rawValue: _value) {
                    p5 = _enum
                }
            }
            guard 
                let type = _type,
                let p6 = _p6,
                let p7 = _p7
            else { return nil}
            return PRHome_page(
                type: type,
                p6: p6,
                p7: p7,
                type1: type1,
                p3: p3,
                p4: p4,
                p5: p5,
                blk: nil
            )
        }
    }
*/
  • Push
let para = Router.PRHome_page(type: .a, p6: .c, p7: 100)
self.navigator.push(Router.home_page, context: para)

// or
self.navigator.push("\(Router.home_page)?type=a&type1=b&p7=1")

Author

[email protected]

License

URLNavigatorExt is available under the MIT license. See the LICENSE file for more info.

urlnavigatorext's People

Contributors

cdoky avatar

Stargazers

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

Watchers

 avatar  avatar

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.