Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve/routable #25

Merged
merged 5 commits into from
May 6, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
}
}