SwiftRouter 1.0

SwiftRouter 1.0

TestsTested
LangLanguage SwiftSwift
License MIT
ReleasedLast Release Jun 2015
SPMSupports SPM

Maintained by Ramy Kfoury.



A Swift Router Implementation.

Requirements

  • iOS 8+
  • Xcode 6.3+

Installation

or CocoaPods:

pod 'SwiftMessageBar'

Usage

To use the router, first create an instance of it in your AppDelegate class, and then update the following method:

func application(application: UIApplication, openURL url: NSURL, sourceApplication: String?, annotation: AnyObject?) -> Bool {
        return router.routeURL(url)
    }

Adding a route requires only a route parameter, and a closure to implement your action

addRoute(yourCustomRoute) { [unowned self] parameters in
            // present a view controller or anything you like to do when this route is detected
        }

The closure returns to you the parsed parameters, which can be either path parameters or query parameters. Here's an example:

route = scheme://host/path/parameter1/value1?parameter2=value2
parameters = [
"parameter1": "value1"
"parameter2": "value2"
]

To call a route from anywhere in your app:

UIApplication.sharedApplication().openURL(URL)

TODO

  • Investigate using NSURLComponents for better parsing of routes

Licence

SwiftRouter is released under the MIT license. See LICENSE for details