Created
May 10, 2022 06:12
-
-
Save YanSte/bd242e44d6a06b0f6a1b3485153b7763 to your computer and use it in GitHub Desktop.
URL StaticString
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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