---
title: maniramezan/urlmacro
framework: Swift Package Catalog
role: article
path: packages/maniramezan/urlmacro
---

# maniramezan/urlmacro

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](https://docs.swift.org/swift-book/documentation/the-swift-programming-language/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`:

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

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

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

## Usage

```swift 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:

```swift 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](LICENSE) for details.

## Package Metadata

Repository: maniramezan/urlmacro

Default branch: main

README: README.md
