Go to file
Jhonatan A 89f56eb029 Create swift.yml 2022-08-02 00:20:10 -05:00
.github/workflows Create swift.yml 2022-08-02 00:20:10 -05:00
.swiftpm/xcode/package.xcworkspace/xcshareddata Initial Commit 2022-06-13 17:17:33 -05:00
Plugins/SafeURLPlugin Moved linting to separate framework 2022-07-17 03:37:03 -05:00
Sources Testing: Replaced Playground with proper tests 2022-08-01 23:43:48 -05:00
Tests/SafeURLTests Testing: Replaced Playground with proper tests 2022-08-01 23:43:48 -05:00
.gitignore Initial Commit 2022-06-13 17:17:33 -05:00
LICENSE Create LICENSE 2022-08-01 17:23:45 -05:00
Package.resolved Dependencies: XcodeIssueReporting updated 2022-08-01 20:03:51 -05:00
Package.swift Testing: Replaced Playground with proper tests 2022-08-01 23:43:48 -05:00
README.md Documentation: Basic code documentation 2022-08-01 20:00:19 -05:00

README.md

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.