docs/Structs/MediaType.html
public struct MediaType : CustomStringConvertible
extension MediaType: Equatable
extension MediaType: Hashable
The media type (formerly known as MIME type) is a standardized way to indicate the nature and format of a document. This struct consists of a catagorical topLevelType and specific subtype seperated by a “/” (e.g. “text/plain”). In HTTP, The media type is sent as the first section of the “Content-Type” header and is case insensitive.
let mediaType = MediaType(type: .application, subtype: "json")
print(mediaType.description)
// Prints ("application/json")
`
TopLevelType
`
An enum of all recognized top-level media types (categories). See: https://www.iana.org/assignments/media-types/media-types.xhtml
Swift
public enum TopLevelType : String
Media type components
`
topLevelType
`
The topLevelType represents the category of the MediaType (e.g. “audio”).
Swift
public let topLevelType: TopLevelType
`
subType
`
The subtype is the specific MediaType (e.g. “html”).
Swift
public let subType: String
Initializers
`
init(type:subType:)
`
Initialize a MediaType instance with a TopLevelType type and String subtype. If no subtype is provided it will default to “*” representing all subtypes.
let mediaType = MediaType(type: .application, subtype: "json")
Swift
public init(type: TopLevelType, subType: String = "*")
`
init(_:)
`
Initialize a MediaType instance from a String. If no subtype is provided it will default to “*” representing all subtypes. If the string preceding the first “/” is not a valid TopLevelType the initializer will return nil.
let mediaType = MediaType("application/json")
Swift
public init?(_ mimeType: String)
Helper Constructors
`
json
`
Helper constructor for the “application/json” media type
let mediaType = MediaType.json
print(mediaType.description)
// Prints ("application/json")
Swift
public static let json: MediaType
`
urlEncoded
`
Helper constructor for the “application/x-www-form-urlencoded” media type
let mediaType = MediaType.urlEncoded
print(mediaType.description)
// Prints ("application/x-www-form-urlencoded")
Swift
public static let urlEncoded: MediaType
Protocol conformance
`
description
`
Returns the media type, as a String structured: topLevelType/subtype. Required for CustomStringConvertible conformance.
print(mediaType.description)
// Prints ("application/json")
Swift
public let description: String
`
==(_:_:)
`
Compares two MediaTypes returning true if they are equal. Required for Equatable conformance.
`
hashValue
`