Skip to content

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.

3 participants