Skip to content

Commit

Permalink
Update README
Browse files Browse the repository at this point in the history
  • Loading branch information
giginet committed Jul 8, 2018
1 parent 98af62d commit f8b650e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
codeCoverageEnabled = "YES"
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
<TestableReference
Expand Down
14 changes: 8 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

Route URL schemes easily.

Crossroad is URL router focused on handling Custom URL Scheme.
Crossroad is an URL router focused on handling Custom URL Scheme.
Using this, you can route multiple URL schemes and fetch arguments and parameters easily.

This library is developed in working time for Cookpad.
Expand Down Expand Up @@ -45,23 +45,23 @@ router.register([
return true
}),
("pokedex://pokemons/:pokedexID", { context in
guard let pokedexID: Int = try? context.argument(for: "pokedexID") else {
guard let pokedexID: Int? = try? context.argument(for: "pokedexID") else {
// pokedexID must be Int
return false
}
if !Pokedex.isExist(pokedexID) { // Find the Pokémon by ID
return false
}
presentPokedexDetailViewController(for: pokedex)
presentPokedexDetailViewController(for: pokedexID)
return true
}),
// ...
])

let canRespond25 = router.responds(to: URL(string: "pokedex://pokemons/25")!) // Pikachu(No. 25) is exist! so it returns true
let canRespond9999 = router.responds(to: URL(string: "pokedex://pokemons/9999")!) // No. 9999 is unknown. so it returns false
router.openIfPossible(URL(string: "pokedex://pokemons/25")) // Open Pikachu page
router.openIfPossible(URL(string: "pokedex://pokemons?type=fire")) // Open list of fire Pokémons page
router.openIfPossible(URL(string: "pokedex://pokemons/25")!) // Open Pikachu page
router.openIfPossible(URL(string: "pokedex://pokemons?type=fire")!) // Open list of fire Pokémons page
```

In common use case, you should call `router.openIfPossible` on `UIApplicationDelegate` method.
Expand Down Expand Up @@ -92,6 +92,8 @@ let generation: Int? = context.parameter(for: "generation") // 1

Currently supported type is `Int`, `Int64`, `Float`, `Double`, `Bool`, `String` and `URL`.

You can also skip schemes on URLs. URLPattern `/search/:keyword` means `pokedex://search/:keyword` on the router.

### Enum argument

You can use enum as arguments by implementing `Extractable`.
Expand All @@ -106,7 +108,7 @@ enum Type: String, Extractable {
}

// matches: pokedex://pokemons?type=fire
let type: Type = context.parameter(for: "type") // .fire
let type: Type? = context.parameter(for: "type") // .fire
```

### Comma-separated list
Expand Down

0 comments on commit f8b650e

Please sign in to comment.