Latest 0.7.7
Homepage https://github.com/bigL055/Routable
License MIT
Platforms ios 8.0, requires ARC
Authors

Routable

CI Status
Version
License
Platform

Example

gif

安装

  • CocoaPods:

    pod "SPRoutable"

简介

  • 导入

    • swift
    import SPRoutable
    • objc
    #import<SPRoutable/Routable.h>
  • 示例

    • 建立目标类用于接受Routable调用

      • 目标类为swift,且存在于Frameworks中,则需要在头部添加@objc(类名)

      • 目标类只会init一次,除非手动清除
      • 类名与函数名具有默认前缀(可自行配置)
      • swift示例:
    @objc(Router_swift)
    class Router_swift: NSObject {
    var flag = true
    
    @objc func router_a(params:[String: Any]) -> UIViewController {
      let vc = UIViewController()
      vc.view.backgroundColor = UIColor.blue
      return vc
    }
    
    @objc func router_b() -> UIView {
      let view = UIView()
      view.frame = CGRect(x: 0, y: 300, width: 300, height: 300)
      view.backgroundColor = flag ? UIColor.red : UIColor.blue
      flag = !flag
      return view
    }
    
    @objc func router_c(params: [String: Any] = [:]) {
      let alert = UIAlertController()
      alert.title = #function
      alert.message = params.description
      let action = UIAlertAction(title: "确定",
                                 style: UIAlertActionStyle.cancel,
                                 handler: nil)
      alert.addAction(action)
      UIApplication.shared.keyWindow?.rootViewController?.present(alert, animated: true, completion: nil)
    }
    
    @objc func router_notice() {
    print(#function + "router_notice")
    }
    }
    • 可以这样使用:
    get viewController:
    guard let vc = Routable.viewController(url: "http://swift/a") else { return }
    
    get view:
    guard let v = Routable.view(url: "http://swift/b") else { return }
    
    get object:
    guard let v: UIView = Routable.object(url: "http://swift/b") else { return }
    
    get function:
    Routable.executing(url: "http://swift/c")
    
    // 需要通知对象存活保证
    send noice:
    Routable.noice(url:"http://swift/notice")
  • 路由配置参数配置:

    Routable.classPrefix = "Router_"  // defalut: "Router_"
    Routable.funcPrefix  = "router_"  // defalut: "router_"
    Routable.paramName   = "Params"   // defalut: "Params"
    Routable.scheme        = "scheme"   // defalut: ""

Author

linger, [email protected]

License

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

Latest podspec

{
    "name": "SPRoutable",
    "version": "0.7.7",
    "summary": "u57fau7840u7684u8defu7531u670du52a1",
    "homepage": "https://github.com/bigL055/Routable",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "lin": "[email protected]"
    },
    "source": {
        "git": "https://github.com/bigL055/Routable.git",
        "tag": "0.7.7"
    },
    "platforms": {
        "ios": "8.0"
    },
    "source_files": [
        "Sources/*/**",
        "Sources/*/*/**",
        "Sources/**"
    ],
    "public_header_files": [
        "Sources/Routable.h"
    ],
    "requires_arc": true,
    "pod_target_xcconfig": {
        "SWIFT_VERSION": "4.0"
    },
    "pushed_with_swift_version": "3.0"
}

Pin It on Pinterest

Share This