URL
is a freestanding Swift macro that provides an unwrapped Foundation URL
for the string literal argument.
The macro checks the validity of the literal and throws an error if it does not represent a valid Foundation URL
.
import URL
let url = #URL("https://www.apple.com")
This will automatically generate the following code:
URL(string: "https://www.apple.com")!
The package can be installed using Swift Package Manager. To add URL
to your Xcode project, select File > Add Package Dependancies... and search for the repository URL: https://github.com/davidsteppenbeck/URL.git
.
URL
is available under the MIT license. See the LICENSE file for more info.
The URL
macro example is described in detail in Antoine v.d. Lee's blog post.