Swiftpack.co - jhonatn/SwiftSafeURL as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by jhonatn.
jhonatn/SwiftSafeURL 0.4.2
[DEPRECATED by Swift Macros and Xcode 15] Compile-time-checked URLs
⭐️ 134
🕓 1 year ago
macOS
.package(url: "https://github.com/jhonatn/SwiftSafeURL.git", from: "0.4.2")

SafeURL

Tool for avoiding using the URL(string:) initializer with optional result, instead introducing a compile time URL validity check. Note, this does not check for website availability, but if the URL is formatted correctly.

Installation

Swift Package Manager

The Swift Package Manager is a tool for automating the distribution of Swift code and is integrated into the swift compiler.

Once you have your Swift package set up, adding SafeURL as a dependency is as easy as adding it to the dependencies value of your Package.swift.

dependencies: [
    .package(url: "https://github.com/baguio/SwiftSafeURL")
],
targets: [
    .target(
        name: "<MyTargetName>",
        dependencies: ["SafeURL"],
        plugins: ["SafeURLPlugin"]
    ),
]

Example

// This will compile
let validUrl = URL(safeString: "https://example.tld")
// This won't
let invalidUrl = URL(safeString: "https://example./tld")

SafeURL requires its parameter to be a single simple string literal

If a file contains the comment // safeurl:warn, invalid URLs in this file will be compiled and will show a warning instead of an error. Note that this is not recommended, as this will still cause a force-stop on runtime.

GitHub

link
Stars: 134
Last commit: 1 year ago
Advertisement: IndiePitcher.com - Cold Email Software for Startups

Dependencies

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics