Skip to content

maniramezan/URLMacro

Repository files navigation

URLMacro

CI License: MIT

A Swift freestanding expression macro that validates URLs at compile time. Never crash from a malformed URL string again — #URL("...") guarantees the URL is valid before your code even runs.

Swift Macros

Swift Macros (introduced in Swift 5.9) enable compile-time code generation and validation. URLMacro leverages this to move URL validation from runtime to compile time, catching invalid URLs as build errors rather than runtime crashes.

Installation

Add URLMacro to your Package.swift:

dependencies: [
    .package(url: "https://github.com/maniramezan/URLMacro", from: "1.0.0")
]

Then add "URLMacro" to your target's dependencies:

.target(
    name: "MyApp",
    dependencies: ["URLMacro"]
)

Usage

import URLMacro

// Compile-time validated URL — guaranteed to be valid
let apple = #URL("https://www.apple.com")
let api = #URL("https://api.example.com/v1/users?page=1#top")

Invalid URLs produce compile-time errors:

let bad = #URL("not a url")
// error: #URL requires a valid URL literal

let interpolated = #URL("https://\(host).com")
// error: #URL does not support string interpolation

License

MIT — see LICENSE for details.

About

A Swift macro that validates URLs at compile time. Use #URL("...") for guaranteed-valid URL values with zero runtime overhead.

Resources

License

Contributing

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages