3.0.0
Crossroad 3.0.0 includes dramatically changes.
Careful treating URL in its RFC #18
According to the URL RFC, URL schemes and hosts must be case-insensitive.
However, other path components must be case-sensitive.
Crossroad now treats case-insensitive URL.
router = DefaultRouter(scheme: "pokedex")
router.register([
("/pokemons", { context in
let type: Type? = context[parameter: "type"]
presentPokedexListViewController(for: type)
return true
}),
// ...
])
let canRespond25 = router.responds(to: URL(string: "POKEDEX://POKEMONS")!) // Accept!!!
Support subscript #22
You can get arguments and parameters via []
.
let pokemonID: Int = context[argument: "pokemonID"]
let query: String = context[parameter: "query"]
More Support relative path #17
I recommend to use relative path for routing patterns especially for Universal Links. It should be readable.
router = DefaultRouter(url: URL(string: "https://my-awesome-pokedex.com")!)
router.register([
("/pokemons", { context in
let type: Type? = context[parameter: "type"]
presentPokedexListViewController(for: type)
return true
}),
// ...
])
Introduce URLParser
#16
In some use cases (such a complex applications), you need to use separated URL parser.
Now, Crossroad 3 provides URLParser
to make Context.
let parser = URLParser<Void>()
let context = parser.parse(URL(string: "pokedex:/pokemons/25")!,
in: URLPattern("pokedex://pokemons/:id")))
Rename Extractable
to Parsable
#19
Now rename Extractable
to Parsable
. You have to use constractors instead of the static methods.
Before
public protocol Extractable {
static func extract(from: String) -> Self?
}
After
public protocol Parsable {
init?(from: String)
}