Skip to content

Commit

Permalink
Improved examples.
Browse files Browse the repository at this point in the history
  • Loading branch information
Calyd committed Mar 23, 2022
1 parent 82c1011 commit 22c601b
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 14 deletions.
15 changes: 4 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,14 +110,9 @@ For example, you can request the list of available products in JSON from an imag
var request = URLRequest(url: URL(string: "https://example-store.com/products")!)
let contentType: MediaType = "application/json"

request.setValue(
"Content-Type",
forHTTPHeaderField: "\(contentType)"
) // is equivalent to
request.setValue(
"Content-Type",
forHTTPHeaderField: contentType.description
)
// The following two statements are equivalent
request.setValue("Content-Type", forHTTPHeaderField: "\(contentType)")
request.setValue("Content-Type", forHTTPHeaderField: contentType.description)

let (_, response) = try await URLSession.shared.data(for: request)
```
Expand All @@ -128,9 +123,7 @@ This means you can use ``MediaType``s in sets or dictionaries. For example, you
application supports like so:

```swift
let supportedImages: Set<MediaType> = [
.image(.png()), .image(.gif()), .image(.jpeg())
]
let supportedImages: Set<MediaType> = ["image/png", "image/gif", "image/jpeg"]
```

### Comparing Media Types
Expand Down
2 changes: 1 addition & 1 deletion Sources/MediaType/Font.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import Foundation
/// func isSupported(font: Font) -> Bool {
/// switch font {
/// case .woff, .woff2: return true
/// case .ttf(_, let parameters): return !(parameters ?? [:]).isEmpty
/// case .ttf(_, let parameters?): return !parameters.isEmpty
/// default: return false
/// }
/// }
Expand Down
2 changes: 1 addition & 1 deletion Tests/MediaTypeTests/CodeExamples/CodeExamples+Font.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ extension CodeExamples {
func isSupported(font: Font) -> Bool {
switch font {
case .woff, .woff2: return true
case .ttf(_, let parameters): return !(parameters ?? [:]).isEmpty
case .ttf(_, let parameters?): return !parameters.isEmpty
default: return false
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,9 @@ extension CodeExamples {
XCTAssertFalse(isSupported("application/atom"))
XCTAssertFalse(isSupported("application/atom;charset=utf-8"))
}

func test_supported_media_types() {
let supportedImages: Set<MediaType> = ["image/png", "image/gif", "image/jpeg"]
XCTAssertEqual(supportedImages, [.image(.png()), .image(.jpeg()), .image(.gif())])
}
}
2 changes: 1 addition & 1 deletion UtilityScripts/MediaDocumentations.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ export const mediaDocumentations = {
"func isSupported(font: Font) -> Bool {",
" switch font {",
" case .woff, .woff2: return true",
" case .ttf(_, let parameters): return !(parameters ?? [:]).isEmpty",
" case .ttf(_, let parameters?): return !parameters.isEmpty",
" default: return false",
" }",
"}",
Expand Down

0 comments on commit 22c601b

Please sign in to comment.