{"id":765,"url":"https://github.com/IanKeen/IKRouter","last_synced_at":"2025-07-30T19:32:12.723Z","repository":{"id":56914967,"uuid":"45214817","full_name":"IanKeen/IKRouter","owner":"IanKeen","description":"URLScheme router than supports auto creation of UIViewControllers for associated url parameters to allow creation of navigation stacks","archived":false,"fork":false,"pushed_at":"2015-10-31T21:40:14.000Z","size":194,"stargazers_count":92,"open_issues_count":0,"forks_count":5,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-11-15T15:42:47.569Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/IanKeen.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-10-29T22:36:27.000Z","updated_at":"2024-01-19T22:32:47.000Z","dependencies_parsed_at":"2022-08-21T03:20:43.131Z","dependency_job_id":null,"html_url":"https://github.com/IanKeen/IKRouter","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/IanKeen%2FIKRouter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/IanKeen%2FIKRouter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/IanKeen%2FIKRouter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/IanKeen%2FIKRouter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/IanKeen","download_url":"https://codeload.github.com/IanKeen/IKRouter/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":228178885,"owners_count":17881104,"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:30.849Z","updated_at":"2024-12-04T19:31:56.834Z","avatar_url":"https://github.com/IanKeen.png","language":"Swift","funding_links":[],"categories":["App Routing","Libs","URL Scheme"],"sub_categories":["Other free courses","Getting Started","App Routing"],"readme":"# IKRouter\n\n## What does it do?\nOnce you have made your `UIViewController`s conform to `Routable` you can register them with the parameters that they represent in your registered url-scheme routes. `IKRouter` is then able to create an array of `UIViewController`s for you to display when a valid url is handled. All you need to do then is display them!\n\n`IKRouter` can also handle routes in the traditional way by simply registering a route and handling it with a funciton/closure and the two methods can also be used together.\n\nAn example route is:\n```\nmyapp://project/:projectId/item/:itemId\n```\nNote that routes must include the scheme (`myapp://`), url parameters need to be prefixed with a colon (`:`) and query strings dont need to be included when registering a route as they are included when the route is matched.\n\n## Using Routables\nTo use the `Routable`s to automatically create your UI stack\n\n1. Make any `UIViewController` that can be linked to a route parameter conform to `Routable`.\n2. Register these with your `IKRouter` instance.\n3. Register the routes that _use_ those parameters.\n4. Handle the chain of `UIViewController`s via the `routableHandler` closure/function.\n\n## The Routable protocol\nThe `Routable` protocol consists of a single simple method which when give a `MatchedRoute` returns an instance of the `Routable`.\n\n```swift\nprotocol Routable {\n    static func instanceForRoute(route: MatchedRoute) -\u003e Routable?\n}\n```\n\n`MatchedRoute` instances provide all the details needed to pass information through to `Routables` like matched parameters and their values as well as query string.\n\n## Routable Example\nOnce your `UIViewController`s are `Routable` simply do the following:\n\n```swift\nlet navController = UINavigationController()\nlet router = IKRouter()\nrouter\n    .registerRoutableWithParameter(ProjectViewController.self, parameter: \":projectId\")\n    .registerRoutableWithParameter(ItemViewController.self, parameter: \":itemId\")\n    .registerRouteHandler(\"myapp://project/:projectId/item/:itemId\")\n    .registerRouteHandler(\"myapp://project/:projectId\")\n    .routableHandler = { match, viewControllers in\n        navController.setViewControllers(viewControllers, animated: true)\n    }\n```\n\n## Things to note about using Routable\n\n* As many routes can be registered as you want in any combination as long as each one is:\n    * Unique\n    * Has a `Routable` registered for all parameters\n* If a route comes through and there is a parameter without a `Routable` the default handler will be used (if provided)\n* When registering a _route_ there is a `handler` parameter. This can be omitted when using `Routable`s.\n\n## Non Routable Example\nIf you have routes which might not suit the _automatic_ functionality provided by `Routable`s you can also register individual routes with their own handlers\n\n```swift\nlet router = IKRouter()\nrouter\n    .registerRouteHandler(\"myapp://project/:projectId/item/:itemId\") { match in\n        //create view controllers and show here...\n        return true\n    }\n    .registerRouteHandler(\"myapp://project/:projectId/users/:userId\") { match in\n        //create view controllers and show here...\n        return true /* return false if we didn't handle the route */\n    }\n```\nNOTE: The handler for each route is used here (unlike above)\n\n## UIViewController Presentation\nEvery app has a slightly different UI hierarchy/architecture... for this reason `IKRouter` does not provide and automatic handling of `UIViewController` presentation but instead allows you to handle that yourself. Instead I have provided a `UINavigationController` extension that you can use to display the stack in different ways.\n\nCurrently there is just a simple method that will take a stack of `UIViewController`s; push all but the last and _present_ the last item in the stack like so:\n\n```swift\nrouter.routableHandler = { match, viewControllers in\n    navController.setViewControllersPresentingLast(viewControllers, animatedSet: true, animatedPresent: true)\n}\n```\n\nIf there are other means of displaying a stack you think would be useful here feel free to add an issue or pull request, both are welcome!\n\n# Installation\nInstall via cocoapods by adding the following to your Podfile\n\n```\npod \"IKRouter\", \"~\u003e1.0\"\n```\n\nor manually by adding the source files from the IKRouter subfolder to your project.\n\n# The rest...\nThere is an included app so you can see it in action.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FIanKeen%2FIKRouter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FIanKeen%2FIKRouter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FIanKeen%2FIKRouter/lists"}