Enumerations
The following enumerations are available globally.
-
Declaration
Swift
public enum Anythingextension Anything: CustomStringConvertibleextension Anything: MediaSubtypeextension Anything: RawRepresentableextension Anything: Hashable -
Represents the
applicationmedia type. See the official documentation for details.You typically use
Applicationas aMediaType.let application = Application.atom(.xml, ["charset": "utf-8"]) let mediaType = MediaType.application(application) // Creates: application/atom+xml;charset=utf-8You can use standard
switchstatement 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: falseSee moreSee also
MediaTypeDeclaration
Swift
public enum Applicationextension Application: CustomStringConvertibleextension Application: RawRepresentableextension Application: MediaSubtypeextension Application: Hashable -
Represents the
audiomedia type. See the official documentation for details.You typically use
Audioas aMediaType.let audio = Audio.ac3(nil, ["rate": 32000]) let mediaType = MediaType.audio(audio) // Creates: audio/ac3;rate=32000You can use standard
switchstatement 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: falseSee moreSee also
MediaTypeDeclaration
Swift
public enum Audioextension Audio: CustomStringConvertibleextension Audio: RawRepresentableextension Audio: MediaSubtypeextension Audio: Hashable -
Represents the
fontmedia type. See the official documentation for details.You typically use
Fontas aMediaType.let font = Font.ttf(nil, ["layout": "oat,aat"]) let mediaType = MediaType.font(font) // Creates: font/ttf;layout=oat,aatYou can use standard
switchstatement 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: falseSee moreSee also
MediaTypeDeclaration
Swift
public enum Fontextension Font: CustomStringConvertibleextension Font: RawRepresentableextension Font: MediaSubtypeextension Font: Hashable -
Represents the
imagemedia type. See the official documentation for details.You typically use
Imageas aMediaType.let image = Image.png() let mediaType = MediaType.image(image) // Creates: image/pngYou can use standard
switchstatement 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: falseSee moreSee also
MediaTypeDeclaration
Swift
public enum Imageextension Image: CustomStringConvertibleextension Image: RawRepresentableextension Image: MediaSubtypeextension 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
MediaTypecases.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
othercase of a particular media type.
See more"application/vnd.efi.img" // is equivalent to MediaType.application(.other("vnd.efi.img"))Declaration
Swift
public enum MediaTypeextension MediaType: CustomStringConvertibleextension MediaType: RawRepresentableextension MediaType: ExpressibleByStringLiteralextension MediaType: Hashable -
Represents the
messagemedia type. See the official documentation for details.You typically use
Messageas aMediaType.let message = Message.http() let mediaType = MediaType.message(message) // Creates: message/httpYou can use standard
switchstatement 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: falseSee moreSee also
MediaTypeDeclaration
Swift
public enum Messageextension Message: CustomStringConvertibleextension Message: RawRepresentableextension Message: MediaSubtypeextension Message: Hashable -
Represents the
modelmedia type. See the official documentation for details.You typically use
Modelas aMediaType.let model = Model.step() let mediaType = MediaType.model(model) // Creates: model/stepYou can use standard
switchstatement 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: falseSee moreSee also
MediaTypeDeclaration
Swift
public enum Modelextension Model: CustomStringConvertibleextension Model: RawRepresentableextension Model: MediaSubtypeextension Model: Hashable -
Represents the
multipartmedia type. See the official documentation for details.You typically use
Multipartas aMediaType.let multipart = Multipart.formData() let mediaType = MediaType.multipart(multipart) // Creates: multipart/form-dataYou can use standard
switchstatement 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: falseSee moreSee also
MediaTypeDeclaration
Swift
public enum Multipartextension Multipart: CustomStringConvertibleextension Multipart: RawRepresentableextension Multipart: MediaSubtypeextension Multipart: Hashable -
Represents the media type suffixes.
The library allows all
MediaTypes 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+zipYou can access a media type’s suffix by matching using a
switchstatement:
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 Suffixextension Suffix: RawRepresentableextension Suffix: CustomStringConvertibleextension Suffix: ExpressibleByStringLiteralextension Suffix: Hashable -
Represents the
textmedia type. See the official documentation for details.You typically use
Textas aMediaType.let text = Text.html() let mediaType = MediaType.text(text) // Creates: text/htmlYou can use standard
switchstatement 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: falseSee moreSee also
MediaTypeDeclaration
Swift
public enum Textextension Text: CustomStringConvertibleextension Text: RawRepresentableextension Text: MediaSubtypeextension Text: Hashable -
Represents the
videomedia type. See the official documentation for details.You typically use
Videoas aMediaType.let video = Video.mp4() let mediaType = MediaType.video(video) // Creates: video/mp4You can use standard
switchstatement 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: falseSee moreSee also
MediaTypeDeclaration
Swift
public enum Videoextension Video: CustomStringConvertibleextension Video: RawRepresentableextension Video: MediaSubtypeextension Video: Hashable