FWRouter
中文版本请查看这里
FWRouter 是一个高性能的 trie-node 路由,灵感来自 Vapor/routing
这不仅仅是一个服务器路由,还是一个 iOS UI 路由,您可以用它来构建自己的 iOS 应用。
示例
使用git clone https://github.com/JianweiWangs/FWRouter.git && cd FWRouter && make
快速获取和构建源代码。
还有一些脚本帮助您开发和提交工单。
# install dependence and open project
make
# install dependence
make install
# build test
make test
# open project
make open
# quit Xcode
make quit
在您提交工单之前,请确保测试通过。
使用方法
URL 匹配
let router = FWRouterManager.shared.router
// url match
route.match("scheme://host/path") { (target) -> Bool in
let demoVC = DemoViewController()
target.navigation?.pushViewController(demoVC, animated: true)
return true
}
route.route(url: "scheme://host/path")
路径参数
router.match("scheme://host", "parameter", String.parameter, use: { (target) -> Bool in
print(target.url) // scheme://host/parameter/param0
print(target.pathParamters.next(String.self)) // "param0"
return true
})
router.route(url: "scheme://host/parameter/param0")
参数
router.match("scheme://host/path", "/thridParameter", use: { (target) -> Bool in
print(target.parameters["name"] as? String) //"wangjianwei"
return true
})
router.route(
url: "scheme://host/path/thridParameter",
parameters: ["name": "wangjianwei"]
)
需求
此库需要 iOS 8.0+
,Xcode 9.0+
和 Swift 4.0+
。
安装
FWRouter 通过 CocoaPods 提供。要安装它,只需将以下行添加到您的 Podfile 文件中
pod 'FWRouter'
作者
JianweiWangs,[email protected]
许可证
FWRouterModule 以 MIT 许可证提供。有关更多信息,请参阅 LICENSE 文件。