Skip to content

Instance Method

encode(_:userInfo:)

Encodes the supplied Encodable object to String.
func encode<E>(_ encodable: E, userInfo: [CodingUserInfoKey : any Sendable] = [:]) throws -> String where E : Encodable

Parameters

encodable

Generic Encodable object (E) to encode.

userInfo

Overrides the default coder user info.

Return Value

Encoded String

Discussion

print(user) // User
let data = try URLEncodedFormEncoder().encode(user)
print(data) // "name=Vapor&age=3"

Throws

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