Skip to content

Instance Method

get(_:as:)

Grabs the named parameter from the parameter bag, casting it to a LosslessStringConvertible type.
func get<T>(_ name: String, as type: T.Type = T.self) -> T? where T : LosslessStringConvertible

Parameters

name

The name of the parameter to be retrieve.

type

The type to cast the parameter value to.

Return Value

The value of the parameter, if it exists.

Discussion

For example GET /posts/:post_id/comments/:comment_id would be fetched using:

let postID = parameters.get("post_id", as: Int.self)
let commentID = parameters.get("comment_id", as: Int.self)