Skip to content

Instance Method

decode(_:from:)

Decodes an instance of the supplied Decodable type from a String.
func decode<D>(_: D.Type, from string: String) throws -> D where D : Decodable

Parameters

decodable

A Decodable type D to decode.

string

String to decode a D from.

Return Value

An instance of D.

Discussion

print(data) // "name=Vapor&age=3"
let user = try URLEncodedFormDecoder().decode(User.self, from: data)
print(user) // User

Throws

Any error that may occur while attempting to decode the specified type.