Merge branch 'feature/url-stringliteral' into develop

This commit is contained in:
Adam Laszlo Rocska 2023-01-22 10:53:25 +01:00
commit 49abbea360
No known key found for this signature in database
GPG Key ID: D9EC1E93111AFFA7
3 changed files with 32 additions and 0 deletions

View File

@ -0,0 +1,17 @@
import Foundation
extension URL: ExpressibleByStringLiteral {
/// A convenience initializer that allows you to express a
/// [`URL`](https://developer.apple.com/documentation/foundation/url) using a string literal.
///
/// ```swift
/// let assignmentExample: URL = "https://www.21gram.consulting/en-US"
/// let (pageDownloadExample, _) = try await URLSession.shared.data(from: "https://www.21gram.consulting/en-US")
/// ```
public init(stringLiteral value: String) {
guard let url = URL(string: value) else {
preconditionFailure("Couldn't initialize URL from literal as it resolved to nil.")
}
self = url
}
}

View File

@ -0,0 +1,9 @@
import Foundation
import XCTest
@testable import Beton
extension URLTest {
func testInit_stringLiteral() {
XCTAssertEqual("https://google.com", URL(string: "https://google.com"))
}
}

View File

@ -0,0 +1,6 @@
import Foundation
import XCTest
@testable import Beton
class URLTest: XCTestCase {
}