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

Feature: conventional routers & routes #24

Merged
merged 8 commits into from
Jan 18, 2016
Merged

Conversation

vadymmarkov
Copy link
Contributor

@zenangst
There are some conventional tools that could be used to organise your route handling code and avoid huge switch cases.

  • Implement Routable protocol to keep your single route navigation code in one place:
struct ProfileRoute: Routable {
  func resolve(arguments: [String: String], navigationController: UINavigationController?) {
    guard let username = arguments["username"] else { return }

    let profileController = profileController(title: username)
    navigationController?.pushViewController(profileController, animated: true)
  }
}
  • Create a Router instance and register your routes:
let router = Router()
router.routes = [
  "profile:{username}" : ProfileRoute(),
  // "logout" : LogoutRoute()
]
  • Parse URL with Compass and navigate to the route with a help of your Router instance.
func application(app: UIApplication,
  openURL url: NSURL,
  options: [String : AnyObject]) -> Bool {
    return Compass.parse(url) { route, arguments in
      router.navigate(route, arguments: arguments,
        navigationController: navigationController)
    }
}

@zenangst
Copy link
Contributor

@vadymmarkov
success

zenangst added a commit that referenced this pull request Jan 18, 2016
@zenangst zenangst merged commit 5124c1c into master Jan 18, 2016
@zenangst zenangst deleted the feature/comventional-routes branch January 18, 2016 12:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants