Enumerations
The following enumerations are available globally.
-
Declaration
Swift
public enum Anything
extension Anything: CustomStringConvertible
extension Anything: MediaSubtype
extension Anything: RawRepresentable
extension Anything: Hashable
-
Represents the
application
media type. See the official documentation for details.You typically use
Application
as aMediaType
.let application = Application.atom(.xml, ["charset": "utf-8"]) let mediaType = MediaType.application(application) // Creates: application/atom+xml;charset=utf-8
You can use standard
switch
statement to access application values.func isSupported(application: Application) -> Bool { switch application { case .senml(.cbor, _), .senml(.json, _), .senml(.xml, _): return true default: return false } } isSupported(application: .senml(.cbor)) // Returns: true isSupported(application: .senml(.json)) // Returns: true isSupported(application: .senml(.xml)) // Returns: true isSupported(application: .senml(.zip)) // Returns: false isSupported(application: .json()) // Returns: false
See also
MediaType
Declaration
Swift
public enum Application
extension Application: CustomStringConvertible
extension Application: RawRepresentable
extension Application: MediaSubtype
extension Application: Hashable
-
Represents the
audio
media type. See the official documentation for details.You typically use
Audio
as aMediaType
.let audio = Audio.ac3(nil, ["rate": 32000]) let mediaType = MediaType.audio(audio) // Creates: audio/ac3;rate=32000
You can use standard
switch
statement to access audio values.func isSupported(audio: Audio) -> Bool { switch audio { case .ac3, .aac, .ogg: return true default: return false } } isSupported(audio: .ac3()) // Returns: true isSupported(audio: .aac()) // Returns: true isSupported(audio: .ogg()) // Returns: true isSupported(audio: .mpeg()) // Returns: false
See also
MediaType
Declaration
Swift
public enum Audio
extension Audio: CustomStringConvertible
extension Audio: RawRepresentable
extension Audio: MediaSubtype
extension Audio: Hashable
-
Represents the
font
media type. See the official documentation for details.You typically use
Font
as aMediaType
.let font = Font.ttf(nil, ["layout": "oat,aat"]) let mediaType = MediaType.font(font) // Creates: font/ttf;layout=oat,aat
You can use standard
switch
statement to access font values.func isSupported(font: Font) -> Bool { switch font { case .woff, .woff2: return true case .ttf(_, let parameters?): return !parameters.isEmpty default: return false } } isSupported(font: .woff()) // Returns: true isSupported(font: .ttf(nil, ["layout": "oat,aat"])) // Returns: true isSupported(font: .ttf()) // Returns: false
See also
MediaType
Declaration
Swift
public enum Font
extension Font: CustomStringConvertible
extension Font: RawRepresentable
extension Font: MediaSubtype
extension Font: Hashable
-
Represents the
image
media type. See the official documentation for details.You typically use
Image
as aMediaType
.let image = Image.png() let mediaType = MediaType.image(image) // Creates: image/png
You can use standard
switch
statement to access image values.func isSupported(image: Image) -> Bool { switch image { case .png, .jpeg, .gif: return true default: return false } } isSupported(audio: .png()) // Returns: true isSupported(audio: .jpeg()) // Returns: true isSupported(audio: .gif()) // Returns: true isSupported(audio: .bmp()) // Returns: false
See also
MediaType
Declaration
Swift
public enum Image
extension Image: CustomStringConvertible
extension Image: RawRepresentable
extension Image: MediaSubtype
extension Image: 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.
See more"application/vnd.efi.img" // is equivalent to MediaType.application(.other("vnd.efi.img"))
Declaration
Swift
public enum MediaType
extension MediaType: CustomStringConvertible
extension MediaType: RawRepresentable
extension MediaType: ExpressibleByStringLiteral
extension MediaType: Hashable
-
Represents the
message
media type. See the official documentation for details.You typically use
Message
as aMediaType
.let message = Message.http() let mediaType = MediaType.message(message) // Creates: message/http
You can use standard
switch
statement to access message values.func isSupported(message: Message) -> Bool { switch message { case .http, .rfc822: return true default: return false } } isSupported(audio: .http()) // Returns: true isSupported(audio: .rfc822()) // Returns: true isSupported(audio: .sip()) // Returns: false
See also
MediaType
Declaration
Swift
public enum Message
extension Message: CustomStringConvertible
extension Message: RawRepresentable
extension Message: MediaSubtype
extension Message: Hashable
-
Represents the
model
media type. See the official documentation for details.You typically use
Model
as aMediaType
.let model = Model.step() let mediaType = MediaType.model(model) // Creates: model/step
You can use standard
switch
statement to access model values.func isSupported(model: Model) -> Bool { switch model { case .step, .iges: return true default: return false } } isSupported(audio: .step()) // Returns: true isSupported(audio: .iges()) // Returns: true isSupported(audio: .mesh()) // Returns: false
See also
MediaType
Declaration
Swift
public enum Model
extension Model: CustomStringConvertible
extension Model: RawRepresentable
extension Model: MediaSubtype
extension Model: Hashable
-
Represents the
multipart
media type. See the official documentation for details.You typically use
Multipart
as aMediaType
.let multipart = Multipart.formData() let mediaType = MediaType.multipart(multipart) // Creates: multipart/form-data
You can use standard
switch
statement to access multipart values.func isSupported(multipart: Multipart) -> Bool { switch multipart { case .formData, .mixed: return true default: return false } } isSupported(audio: .formData()) // Returns: true isSupported(audio: .mixed()) // Returns: true isSupported(audio: .voiceMessage()) // Returns: false
See also
MediaType
Declaration
Swift
public enum Multipart
extension Multipart: CustomStringConvertible
extension Multipart: RawRepresentable
extension Multipart: MediaSubtype
extension Multipart: Hashable
-
Represents the media type suffixes.
The library allows all
MediaType
s to have a suffix. Keep in mind though, that not all such combinations are registered (see the official site for details).It is also possible to create completely custom suffixes by using either the
other(_:)
case directly or a string literal.MediaType.application(.jose(.json)) // Creates: application/jose+json MediaType.application(.jose(.other("custom"))) // Creates: application/jose+custom MediaType.image(.svg("zip")) // Creates: image/svg+zip
You can access a media type’s suffix by matching using a
switch
statement:
See morelet mediaType = MediaType.application(.calendar(.xml)) switch mediaType { case .application(.calendar(let suffix, _)): guard let suffix = suffix else { break } print("Suffix: \(suffix)", "Suffix: +xml") default: print("Unsupported media type: \(mediaType)") }
Declaration
Swift
public enum Suffix
extension Suffix: RawRepresentable
extension Suffix: CustomStringConvertible
extension Suffix: ExpressibleByStringLiteral
extension Suffix: Hashable
-
Represents the
text
media type. See the official documentation for details.You typically use
Text
as aMediaType
.let text = Text.html() let mediaType = MediaType.text(text) // Creates: text/html
You can use standard
switch
statement to access text values.func isSupported(text: Text) -> Bool { switch text { case .html, .css: return true default: return false } } isSupported(audio: .html()) // Returns: true isSupported(audio: .css()) // Returns: true isSupported(audio: .javascript()) // Returns: false
See also
MediaType
Declaration
Swift
public enum Text
extension Text: CustomStringConvertible
extension Text: RawRepresentable
extension Text: MediaSubtype
extension Text: Hashable
-
Represents the
video
media type. See the official documentation for details.You typically use
Video
as aMediaType
.let video = Video.mp4() let mediaType = MediaType.video(video) // Creates: video/mp4
You can use standard
switch
statement to access video values.func isSupported(video: Video) -> Bool { switch video { case .mp4, .H264: return true default: return false } } isSupported(audio: .mp4()) // Returns: true isSupported(audio: .H264()) // Returns: true isSupported(audio: .vc1()) // Returns: false
See also
MediaType
Declaration
Swift
public enum Video
extension Video: CustomStringConvertible
extension Video: RawRepresentable
extension Video: MediaSubtype
extension Video: Hashable