@@ -37,6 +37,7 @@ extension MediaType {
3737 public static let multipartFormData = MediaType ( type: " multipart " , subtype: " form-data " )
3838
3939 public static let textPlain = MediaType ( type: " text " , subtype: " plain " )
40+ public static let textCsv = MediaType ( type: " text " , subtype: " csv " )
4041 public static let textHtml = MediaType ( type: " text " , subtype: " html " )
4142 public static let textCss = MediaType ( type: " text " , subtype: " css " )
4243
@@ -63,6 +64,34 @@ extension MediaType {
6364}
6465// swiftlint:enable missing_docs
6566
67+ // MARK: - UniformTypeIdentifiers
68+
69+ #if canImport(UniformTypeIdentifiers)
70+ import UniformTypeIdentifiers
71+
72+ extension MediaType {
73+ /// Create a media type from a uniform type.
74+ /// - Parameter uniformType: The uniform type (UTType).
75+ @available ( macOS 11 . 0 , iOS 14 . 0 , watchOS 7 . 0 , tvOS 14 . 0 , * )
76+ public init ? ( uniformType: UTType ) {
77+ guard let mimeTypeSplit = uniformType. preferredMIMEType? . split ( separator: " / " ) else { return nil }
78+ guard mimeTypeSplit. count == 2 else { return nil }
79+ self . type = String ( mimeTypeSplit [ 0 ] )
80+ self . subtype = String ( mimeTypeSplit [ 1 ] )
81+ }
82+ }
83+
84+ @available ( macOS 11 . 0 , iOS 14 . 0 , watchOS 7 . 0 , tvOS 14 . 0 , * )
85+ extension UTType {
86+ /// Create a uniform type from a media type.
87+ /// - Parameter mediaType: The media type.
88+ /// - Parameter supertype: Another UTType instance that the resulting type must conform to; for example, UTTypeData.
89+ public init ? ( mediaType: MediaType , conformingTo supertype: UTType = . data) {
90+ self . init ( mimeType: mediaType. _text, conformingTo: supertype)
91+ }
92+ }
93+ #endif
94+
6695// MARK: - Debug
6796
6897extension MediaType : CustomDebugStringConvertible {
0 commit comments