Skip to content

Instantly share code, notes, and snippets.

@eMdOS
Created January 10, 2018 22:54
Show Gist options
  • Save eMdOS/8e4fae2cc512ceca3bb4e8a2a410c028 to your computer and use it in GitHub Desktop.
Save eMdOS/8e4fae2cc512ceca3bb4e8a2a410c028 to your computer and use it in GitHub Desktop.
[Swift] URL: ExpressibleByStringLiteral

Extension:

extension URL: ExpressibleByStringLiteral {
    public init(stringLiteral value: StaticString) {
        guard let url = URL(string: "\(value)") else {
            fatalError("Invalid URL string literal: \(value)")
        }
        self = url
    }
}

Usage:

let url: URL = "https://google.com"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment