Skip to content

Type Method

fileExtension(_:)

Creates a MediaType from a file extension, if possible.
static func fileExtension(_ ext: String) -> HTTPMediaType?

Parameters

ext

File extension (ie., “txt”, “json”, “html”).

Return Value

Newly created MediaType, nil if none was found.

Discussion

guard let mediaType = MediaType.fileExtension("txt") else { ... }