ProductPromotion
Logo

Swift

made by https://0x3d.site

GitHub - skyline75489/SwiftRouter: A URL Router for iOS, written in Swift
A URL Router for iOS, written in Swift. Contribute to skyline75489/SwiftRouter development by creating an account on GitHub.
Visit Site

GitHub - skyline75489/SwiftRouter: A URL Router for iOS, written in Swift

GitHub - skyline75489/SwiftRouter: A URL Router for iOS, written in Swift

SwiftRouter

License MIT Travis-CI Carthage compatible

A URL Router for iOS, written in Swift, inspired by HHRouter and JLRoutes.

Installation

SwiftRouter Version Swift Version Note
Before 1.0.7 2.0 n/a
1.0.7 2.2 n/a
2.0.0 3.0 n/a
2.1.0 3.0 Breaking changes by adopting exception
3.0.0 4.0 @objc should be used with properties

Carthage

SwiftRouter is compatible with Carthage. Add it to your Cartfile:

github "skyline75489/SwiftRouter"

CocoaPods

pod 'JLSwiftRouter'

use_frameworks!

Manually

Add SwiftRouter.swift in your project.

Usage

Routing ViewController

Define properties in your custom ViewController:

class UserViewController: UIViewController {
    @objc var userId:String?
    @objc var username:String?
    @objc var password:String?
}

Map URL to ViewController:

import SwiftRouter

let router = Router.shared
router.map("/user/:userId", controllerClass: UserViewController.self)

Get instance of ViewController directly from the URL. Parameters will be parsed automatically:

let vc = router.matchController("/user/1?username=hello&password=123")!
XCTAssertEqual(vc.userId, "1")
XCTAssertEqual(vc.username, "hello")
XCTAssertEqual(vc.password, "123")

This will load controller using init() method. If you want to load view controller from storyboard - use:

let vc = router.matchControllerFromStoryboard("/user/1?username=hello&password=123", 
                                              storyboardName: "MyStoryboard")!

This 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.

Push custom ViewController:

router.routeURL("/user/123", navigationController: self.navigationController!)
// The custom ViewController will be pushed with parameters.

Routing handler

Define your custom handler function and map it to URL:

router.map("/user/add", handler: { (params:[String: String]?) -> (Bool) in
    XCTAssertNotNil(params)
    if let params = params {
        XCTAssertEqual(params["username"], "hello")
        XCTAssertEqual(params["password"], "123")
    }
    return true
})

Call the handler from router:

router.routeURL("/user/add?username=hello&password=123") 
// The handler function will be called with parameters.

License

MIT License

More Resources
to explore the angular.

mail [email protected] to add your project or resources here ๐Ÿ”ฅ.

Related Articles
to learn about angular.

FAQ's
to learn more about Angular JS.

mail [email protected] to add more queries here ๐Ÿ”.

More Sites
to check out once you're finished browsing here.

0x3d
https://www.0x3d.site/
0x3d is designed for aggregating information.
NodeJS
https://nodejs.0x3d.site/
NodeJS Online Directory
Cross Platform
https://cross-platform.0x3d.site/
Cross Platform Online Directory
Open Source
https://open-source.0x3d.site/
Open Source Online Directory
Analytics
https://analytics.0x3d.site/
Analytics Online Directory
JavaScript
https://javascript.0x3d.site/
JavaScript Online Directory
GoLang
https://golang.0x3d.site/
GoLang Online Directory
Python
https://python.0x3d.site/
Python Online Directory
Swift
https://swift.0x3d.site/
Swift Online Directory
Rust
https://rust.0x3d.site/
Rust Online Directory
Scala
https://scala.0x3d.site/
Scala Online Directory
Ruby
https://ruby.0x3d.site/
Ruby Online Directory
Clojure
https://clojure.0x3d.site/
Clojure Online Directory
Elixir
https://elixir.0x3d.site/
Elixir Online Directory
Elm
https://elm.0x3d.site/
Elm Online Directory
Lua
https://lua.0x3d.site/
Lua Online Directory
C Programming
https://c-programming.0x3d.site/
C Programming Online Directory
C++ Programming
https://cpp-programming.0x3d.site/
C++ Programming Online Directory
R Programming
https://r-programming.0x3d.site/
R Programming Online Directory
Perl
https://perl.0x3d.site/
Perl Online Directory
Java
https://java.0x3d.site/
Java Online Directory
Kotlin
https://kotlin.0x3d.site/
Kotlin Online Directory
PHP
https://php.0x3d.site/
PHP Online Directory
React JS
https://react.0x3d.site/
React JS Online Directory
Angular
https://angular.0x3d.site/
Angular JS Online Directory