Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/cdoky/urlnavigatorext
使用注解自动生成Router以及Router相关参数
https://github.com/cdoky/urlnavigatorext
annotations navigator router sourcery swift
Last synced: about 2 months ago
JSON representation
使用注解自动生成Router以及Router相关参数
- Host: GitHub
- URL: https://github.com/cdoky/urlnavigatorext
- Owner: cdoky
- License: mit
- Created: 2019-11-26T06:09:08.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2023-11-03T06:56:43.000Z (about 1 year ago)
- Last Synced: 2024-10-12T06:10:23.975Z (3 months ago)
- Topics: annotations, navigator, router, sourcery, swift
- Language: Swift
- Homepage:
- Size: 67.4 KB
- Stars: 14
- Watchers: 2
- Forks: 4
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# URLNavigatorExt
[![CI Status](https://img.shields.io/travis/[email protected]/URLNavigatorExt.svg?style=flat)](https://travis-ci.org/[email protected]/URLNavigatorExt)
[![Version](https://img.shields.io/cocoapods/v/URLNavigatorExt.svg?style=flat)](https://cocoapods.org/pods/URLNavigatorExt)
[![License](https://img.shields.io/cocoapods/l/URLNavigatorExt.svg?style=flat)](https://cocoapods.org/pods/URLNavigatorExt)
[![Platform](https://img.shields.io/cocoapods/p/URLNavigatorExt.svg?style=flat)](https://cocoapods.org/pods/URLNavigatorExt)## Example
To run the example project, clone the repo, and run `pod install && sourcery` from the Example directory first.
## Dependencies
- [URLNavigator](https://github.com/devxoul/URLNavigator):Elegant URL Routing for Swift
- [Sourcery](https://github.com/krzysztofzablocki/Sourcery):Meta-programming for Swift, stop writing boilerplate code. http://merowing.info## Installation
URLNavigatorExt is available through [CocoaPods](https://cocoapods.org). To install
it, simply add the following line to your Podfile:```ruby
pod 'URLNavigatorExt'
```## Usage
- install `sourcery`
> `brew install sourcery`
- touch `.sourcery.yml` in ${SRCROOT} [sourcery document](https://cdn.rawgit.com/krzysztofzablocki/Sourcery/master/docs/usage.html)
>
```yml
sources:
- ./${PROJECT_NAME}
templates:
- ./${PROJECT_NAME}/config
output:
./${PROJECT_NAME}/config
- Build Phases
```shell
sourcery
```- AppDelegate.swift
```swift
import URLNavigator
import URLNavigatorExtlet 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`协议
```swift
// 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: TestEnuminit(
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
```swift
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
## License
URLNavigatorExt is available under the MIT license. See the LICENSE file for more info.