Started to document Parameters.
This commit is contained in:
parent
4b6ec5798c
commit
884d1499e8
|
@ -29,7 +29,7 @@ let mediaType = MediaType(rawValue: rawMediaType)
|
|||
|
||||
### Suffixes and Parameters
|
||||
|
||||
Media type ``Suffix``es and parameters are supported both via string literals and ``MediaType`` cases.
|
||||
Media type ``Suffix``es and ``Parameters`` are supported both via string literals and ``MediaType`` cases.
|
||||
|
||||
```swift
|
||||
MediaType.application(.atom(nil, ["charset": "utf-8"])) // is equivalent to
|
||||
|
|
|
@ -1,5 +1,26 @@
|
|||
import Foundation
|
||||
|
||||
/// Represents parameters of ``MediaType``s.
|
||||
///
|
||||
/// A media type may have parameters. For example `text/html;charset=utf-8` defines a media type with UTF-8 charset
|
||||
/// instead of the default ASCII.
|
||||
///
|
||||
/// You can specify arbitrary parameters to *any* of the ``MediaType``s using a Swift
|
||||
/// [dictionary](https://developer.apple.com/documentation/swift/dictionary). Keep in mind though, that not all such
|
||||
/// parameter values are registered (see the
|
||||
/// [official site](https://www.iana.org/assignments/media-types/media-types.xhtml) for details).
|
||||
///
|
||||
/// You can specify parameters by using either the Swift DSL or string literal syntax. Parameters in string variables
|
||||
/// are also supported. The following examples are equivalent:
|
||||
///
|
||||
/// ```swift
|
||||
/// let mediaType = MediaType.audio(.ac3(nil, ["rate": 32_000])) // is equivalent to
|
||||
///
|
||||
/// let mediaType: MediaType = "audio/ac3;rate=32000" // is equivalent to
|
||||
///
|
||||
/// let rawMediaType = "audio/ac3;rate=32000"
|
||||
/// let mediaType = MediaType(rawValue: rawMediaType)
|
||||
/// ```
|
||||
public typealias Parameters = [String: CustomStringConvertible?]
|
||||
|
||||
internal extension DefaultStringInterpolation {
|
||||
|
|
|
@ -0,0 +1,15 @@
|
|||
import XCTest
|
||||
import MediaType
|
||||
|
||||
extension CodeExamples {
|
||||
func test_parameters_use_cases() {
|
||||
let mediaType_A = MediaType.audio(.ac3(nil, ["rate": 32_000]))
|
||||
let mediaType_B: MediaType = "audio/ac3;rate=32000"
|
||||
let rawMediaType = "audio/ac3;rate=32000"
|
||||
let mediaType_C = MediaType(rawValue: rawMediaType)
|
||||
|
||||
XCTAssertEqual(mediaType_A, mediaType_B)
|
||||
XCTAssertEqual(mediaType_A, mediaType_C)
|
||||
XCTAssertEqual(mediaType_B, mediaType_C)
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue