ContentType

public struct ContentType : CustomStringConvertible, Equatable

The ContentType struct represents the common types of Content Types used when sending through the SendGrid API.

  • The first part of the content type, for example text in text/html.

    Declaration

    Swift

    public let type: String
  • The second part of the content type, for example html in text/html.

    Declaration

    Swift

    public let subtype: String
  • The full value of the content type.

    Declaration

    Swift

    public var description: String { get }
  • Initializes the struct with a type and subtype. These two parameters will be combined with a / between to create the value of the Content-Type header.

    Declaration

    Swift

    public init(type: String, subtype: String)

    Parameters

    type

    The first part of the content type, for example text in text/html.

    subtype

    The second part of the content type, for example html in text/html.

  • Initializes the struct with a raw value. The raw value should be a string containing a type and subtype separated by a / character, such as text/html. If the provided value is invalid, nil is returned.

    Declaration

    Swift

    public init?(rawValue: String)

    Parameters

    rawValue

    A String representing the value of the content type.

  • Validates that the content-type has no CLRF characters.

    Declaration

    Swift

    public func validate() throws
  • Represents application/x-www-form-urlencoded encodings.

    Declaration

    Swift

    static let formUrlEncoded: ContentType
  • The application/json content type.

    Declaration

    Swift

    static let json: ContentType
  • The text/plain content type, used for the plain text portion of an email.

    Declaration

    Swift

    static let plainText: ContentType
  • The text/html content type, used for the HTML portion of an email.

    Declaration

    Swift

    static let htmlText: ContentType
  • csv

    The application/csv content type, used for CSV attachments.

    Declaration

    Swift

    static let csv: ContentType
  • pdf

    The application/pdf content type, used for PDF attachments.

    Declaration

    Swift

    static let pdf: ContentType
  • zip

    The application/zip content type, used for Zip file attachments.

    Declaration

    Swift

    static let zip: ContentType
  • png

    The image/png content type, used for PNG images.

    Declaration

    Swift

    static let png: ContentType
  • The image/jpeg content type, used for JPEG images.

    Declaration

    Swift

    static let jpeg: ContentType
  • amp

    The text/x-amp-html content type, used for Google AMP support.

    Declaration

    Swift

    static let amp: ContentType