MediaType
public enum MediaType
extension MediaType: CustomStringConvertible
extension MediaType: RawRepresentable
extension MediaType: ExpressibleByStringLiteral
extension MediaType: Hashable
A type-safe representation of Media Types (or formerly known as MIME types).
You can create a media type in a type-safe manner using one of the possible cases. You can also create media type instances simply using string literals.
let mediaType: MediaType = "application/json" // is equivalent to
MediaType.application(.json())
Media type suffixes and parameters are supported both via string literals and MediaType cases.
let mediaType: MediaType = "application/atom; charset=utf-8" // is equivalent to
MediaType.application(.atom(nil, ["charset": "utf-8"]))
let mediaType: MediaType = "application/atom+xml" // is equivalent to
MediaType.application(.atom(.xml))
let mediaType: MediaType = "application/atom+xml; charset=utf-8" // is equivalent to
MediaType.application(.atom(.xml, ["charset": "utf-8"]))
You can create media type trees using either the string literal syntax, or using the other case of a particular
media type.
"application/vnd.efi.img" // is equivalent to
MediaType.application(.other("vnd.efi.img"))
-
Represents the
applicationmedia type.Represents binary data. Common examples:
application/json,application/octet-stream.For the whole family of
applicationmedia types consult the official IANA documentation.Declaration
Swift
case application(Application) -
Represents the
audiomedia type.Represents audible data. Common examples:
audio/ac3,audio/mpeg.For the whole family of
audiomedia types consult the official IANA documentation.Declaration
Swift
case audio(Audio) -
Represents the
fontmedia type.Represents font or typeface data. Common examples:
font/woff,font/ttf.For the whole family of
fontmedia types consult the official IANA documentation.Declaration
Swift
case font(Font) -
Represents the
imagemedia type.Represents image or graphical data. This includes bitmap and vector images, along with animated image formats. Common examples:
image/jpeg,image/apng.For the whole family of
imagemedia types consult the official IANA documentation.Declaration
Swift
case image(Image) -
Represents the
messagemedia type.Represents embedded message data. Common examples:
message/rfc882,message/http.For the whole family of
messagemedia types consult the official IANA documentation.Declaration
Swift
case message(Message) -
Represents the
modelmedia type.Represents 3D modelling data. Common examples:
model/step,model/3mf.For the whole family of
modelmedia types consult the official IANA documentation.Declaration
Swift
case model(Model) -
Represents the
multipartmedia type.Represents data formed from multiple components, which may have their individual media types. Common examples:
multipart/form-data,multipart/encrypted.For the whole family of
multipartmedia types consult the official IANA documentation.Declaration
Swift
case multipart(Multipart) -
Represents the
textmedia type.Represents textual only data. Common examples:
text/css,text/html.For the whole family of
textmedia types consult the official IANA documentation.Declaration
Swift
case text(Text) -
Represents the
videomedia type.Represents video data. Common examples:
video/mp4,video/H264.For the whole family of
videomedia types consult the official IANA documentation.Declaration
Swift
case video(Video) -
Represents a custom media type that is currently not officially defined.
Represents a custom media type with the given
typeandsubtype. Optionally, you can specify aSuffixandParameters.Declaration
Swift
case other(type: CustomStringConvertible, subtype: CustomStringConvertible, _: Suffix? = nil, _: Parameters? = nil) -
Represents a wildcard media type.
A wildcard media type has a type of
*. A few examples:MediaType.anything(.anything()) // Creates: */* MediaType.anything(.other("dialog")) // Creates: */dialog MediaType.anything(.other("response", .xml)) // Creates: */response+xmlDeclaration
Swift
case anything(Anything) -
The textual representation of the media type.
The string form of a media type follows the pattern:
type/subtype[+suffix][;parameters]. A few examples:MediaType.text(.css()).description // Outputs: text/css MediaType.audio(.ac3(nil, ["rate": 32000])).description // Outputs: audio/ac3;rate=32000 MediaType.application(.atom(.xml, ["charset": "utf-8"])).description // Outputs: application/atom+xml;charset=utf-8Declaration
Swift
public var description: String { get } -
Creates a media type from its raw string value.
Declaration
Swift
public init(rawValue: String)Parameters
rawValueThe raw string value.
-
The raw string value of the media type.
Declaration
Swift
public var rawValue: String { get } -
Creates a media type from a string literal.
Do not call this initializer directly. This rather allows you to use a string literal where you have to provide a
MediaTypenode.Declaration
Swift
public init(stringLiteral value: String) -
Returns a Boolean indicating whether two media types are the same.
Two media types represent the same thing, and thus considered to be equal, if they have the same type, subtype,
SuffixandParameters.Declaration
Swift
public static func == (lhs: `Self`, rhs: `Self`) -> Bool -
Declaration
Swift
public func hash(into hasher: inout Hasher)