{"id":775,"url":"https://github.com/skyline75489/SwiftRouter","last_synced_at":"2025-08-06T13:31:47.197Z","repository":{"id":56916202,"uuid":"43060405","full_name":"skyline75489/SwiftRouter","owner":"skyline75489","description":"A URL Router for iOS, written in Swift","archived":false,"fork":false,"pushed_at":"2019-09-21T02:14:27.000Z","size":76,"stargazers_count":278,"open_issues_count":4,"forks_count":27,"subscribers_count":11,"default_branch":"master","last_synced_at":"2024-12-03T10:44:49.908Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/skyline75489.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-09-24T10:29:06.000Z","updated_at":"2024-11-07T02:07:53.000Z","dependencies_parsed_at":"2022-08-21T03:50:36.724Z","dependency_job_id":null,"html_url":"https://github.com/skyline75489/SwiftRouter","commit_stats":null,"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/skyline75489%2FSwiftRouter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/skyline75489%2FSwiftRouter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/skyline75489%2FSwiftRouter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/skyline75489%2FSwiftRouter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/skyline75489","download_url":"https://codeload.github.com/skyline75489/SwiftRouter/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":228905431,"owners_count":17989761,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-01-05T20:15:31.050Z","updated_at":"2024-12-09T14:30:36.945Z","avatar_url":"https://github.com/skyline75489.png","language":"Swift","funding_links":[],"categories":["App Routing","Libs","Utility","Architecture and State","App Routing [🔝](#readme)"],"sub_categories":["App Routing","Other free courses","Getting Started","Utility"],"readme":"SwiftRouter\n===========\n\n[![License MIT](https://img.shields.io/badge/License-MIT-blue.svg?style=flat)](https://github.com/skyline75489/SwiftRouter/blob/master/LICENSE)\n[![Travis-CI](https://travis-ci.org/skyline75489/SwiftRouter.svg?branch=master)](https://travis-ci.org/skyline75489/SwiftRouter)\n[![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage)\n\nA URL Router for iOS, written in Swift, inspired by [HHRouter](https://github.com/Huohua/HHRouter) and [JLRoutes](https://github.com/joeldev/JLRoutes).\n\n## Installation\n\n| SwiftRouter Version | Swift Version | Note |\n|:------------------:|:--------------------:|:-----|\n| Before 1.0.7 | 2.0 | n/a |\n| 1.0.7 | 2.2 | n/a |\n| 2.0.0 | 3.0 | n/a |\n| 2.1.0 | 3.0 | Breaking changes by adopting exception |\n| 3.0.0 | 4.0 | @objc should be used with properties |\n\n### Carthage\n\nSwiftRouter is compatible with [Carthage](https://github.com/Carthage/Carthage). Add it to your `Cartfile`:\n\n    github \"skyline75489/SwiftRouter\"\n\n### CocoaPods\n\n```ruby\npod 'JLSwiftRouter'\n\nuse_frameworks!\n```\n\n### Manually\n\nAdd `SwiftRouter.swift` in your project.\n\n## Usage\n   \n### Routing ViewController\n\nDefine properties in your custom ViewController:\n\n```swift\nclass UserViewController: UIViewController {\n    @objc var userId:String?\n    @objc var username:String?\n    @objc var password:String?\n}\n```\n\nMap URL to ViewController:\n\n```swift\nimport SwiftRouter\n\nlet router = Router.shared\nrouter.map(\"/user/:userId\", controllerClass: UserViewController.self)\n```\n\nGet instance of ViewController directly from the URL. Parameters will be parsed automatically:\n\n```swift\nlet vc = router.matchController(\"/user/1?username=hello\u0026password=123\")!\nXCTAssertEqual(vc.userId, \"1\")\nXCTAssertEqual(vc.username, \"hello\")\nXCTAssertEqual(vc.password, \"123\")\n```\n\nThis will load controller using init() method. If you want to load view controller from storyboard - use: \n```swift\nlet vc = router.matchControllerFromStoryboard(\"/user/1?username=hello\u0026password=123\", \n                                              storyboardName: \"MyStoryboard\")!\n```\n\nThis code will load controller from storyboard named MyStoryboard.storyboard. Just don't forget to set that controller identifier in storyboard to its class name. In this case ``` UserViewController ```.\n\nPush custom ViewController:\n\n```swift\nrouter.routeURL(\"/user/123\", navigationController: self.navigationController!)\n// The custom ViewController will be pushed with parameters.\n\n```\n\n### Routing handler\n\nDefine your custom handler function and map it to URL:\n\n```swift\nrouter.map(\"/user/add\", handler: { (params:[String: String]?) -\u003e (Bool) in\n    XCTAssertNotNil(params)\n    if let params = params {\n        XCTAssertEqual(params[\"username\"], \"hello\")\n        XCTAssertEqual(params[\"password\"], \"123\")\n    }\n    return true\n})\n```\n\nCall the handler from router:\n\n```swift\nrouter.routeURL(\"/user/add?username=hello\u0026password=123\") \n// The handler function will be called with parameters.\n```\n\n## License\n\n[MIT License](https://github.com/skyline75489/SwiftRouter/blob/master/LICENSE)\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fskyline75489%2FSwiftRouter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fskyline75489%2FSwiftRouter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fskyline75489%2FSwiftRouter/lists"}