Skip to content

Instantly share code, notes, and snippets.

@markiv
Created June 7, 2022 17:50
Show Gist options
  • Save markiv/fb0bf59bdaca07c13f59990df780a8f2 to your computer and use it in GitHub Desktop.
Save markiv/fb0bf59bdaca07c13f59990df780a8f2 to your computer and use it in GitHub Desktop.
prefix operator ^
postfix operator ^
extension URL: ExpressibleByStringLiteral {
/// Conveniently initializes a `URL` from a string literal:
///
/// let url: URL = "https://www.somewhere.com"
public init(stringLiteral value: StringLiteralType) {
self.init(string: value)!
}
/// Conveniently initializes a `URL` from a string literal:
///
/// let url = URL("https://www.somewhere.com")
public init(_ value: StringLiteralType) {
self.init(string: value)!
}
/// This operator conveniently initializes a `URL` from a prefixed string literal:
///
/// let url = ^"https://www.somewhere.com"
@inlinable @inline(__always)
static prefix func ^ (_ value: URL) -> URL { value }
/// This operator conveniently initializes a `URL` from a postfixed string literal:
///
/// let url = "https://www.somewhere.com"^
@inlinable @inline(__always)
static postfix func ^ (_ value: URL) -> URL { value }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment