Skip to content

Commit

Permalink
Merge pull request #25 from hyperoslo/improve/routable
Browse files Browse the repository at this point in the history
Improve/routable
  • Loading branch information
zenangst committed May 6, 2016
2 parents b702df4 + 80629df commit ae65f01
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion Cartfile.resolved
Original file line number Diff line number Diff line change
@@ -1 +1 @@
github "hyperoslo/Sugar" "1.0.3"
github "hyperoslo/Sugar" "1.1.1"
8 changes: 4 additions & 4 deletions CompassTests/iOS/TestRouter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ class TestRoute: Routable {

var resolved = false

func resolve(arguments: [String: String], navigationController: UINavigationController?) {
func resolve(arguments: [String: String], currentController controller: UIViewController) {
resolved = true
}
}

class TestRouter: XCTestCase {

var router: Router!
var navigationController = UINavigationController()
var controller = UIViewController()
var route: TestRoute!

override func setUp() {
Expand All @@ -24,13 +24,13 @@ class TestRouter: XCTestCase {

func testNavigateIfRouteRegistered() {
router.routes["test"] = route
router.navigate("test", arguments: [:], navigationController: navigationController)
router.navigate("test", arguments: [:], from: controller)

XCTAssertTrue(route.resolved)
}

func testNavigateIfRouteNotRegistered() {
router.navigate("test", arguments: [:], navigationController: navigationController)
router.navigate("test", arguments: [:], from: controller)

XCTAssertFalse(route.resolved)
}
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,11 @@ route handling code and avoid huge `switch` cases.
in one place:
```swift
struct ProfileRoute: Routable {
func resolve(arguments: [String: String], navigationController: UINavigationController?) {
func resolve(arguments: [String: String], currentController: UIViewController) {
guard let username = arguments["username"] else { return }

let profileController = profileController(title: username)
navigationController?.pushViewController(profileController, animated: true)
currentController.navigationController?.pushViewController(profileController, animated: true)
}
}
```
Expand Down
2 changes: 1 addition & 1 deletion Sources/iOS/Routable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ import UIKit

public protocol Routable {

func resolve(arguments: [String: String], navigationController: UINavigationController?)
func resolve(arguments: [String: String], currentController: UIViewController)
}
4 changes: 2 additions & 2 deletions Sources/iOS/Router.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ public struct Router {

public init() {}

public func navigate(route: String, arguments: [String: String], navigationController: UINavigationController?) {
public func navigate(route: String, arguments: [String: String], from controller: UIViewController) {
guard let route = routes[route] else { return }

route.resolve(arguments, navigationController: navigationController)
route.resolve(arguments, currentController: controller)
}
}

0 comments on commit ae65f01

Please sign in to comment.