Skip to content

Instantly share code, notes, and snippets.

@YanSte
Created May 10, 2022 06:12
Show Gist options
  • Save YanSte/bd242e44d6a06b0f6a1b3485153b7763 to your computer and use it in GitHub Desktop.
Save YanSte/bd242e44d6a06b0f6a1b3485153b7763 to your computer and use it in GitHub Desktop.
URL StaticString
extension URL {
init(_ staticString: StaticString) {
if let url = URL(string: "\(staticString)") {
self = url
} else {
preconditionFailure("'\(staticString)' does not represent a legal URL")
}
}
}
static let urlString = "http://hello"
// New version
static let url = URL(urlString)
// Old version
static let url = URL(string: "http://hello")! // Need !
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment