MyNameIsURL provides a set of structs used to create URL-matching values. These values can be matched against URLs in a pattern context (usually as part of a switch or if case) or manually by calling their matches(url:) predicate:
include MyNameIsURL
let url = URL(string: "http://example.com")!
switch url {
case Host("example.com"):
// ...
}
Host("example.com").matches(url: url) //> true
A set of logical structs are also provided for complex matching requirements:
let insecureAdminPattern = And(
Or(PathPrefix(["/", "admin"]), PathPrefix(["/", "root"])),
Not(Scheme.https)
)
switch myURL {
case insecureAdminPattern:
fatalError("Admin credentials are not secure!")
// ...
}
MyNameIsURL
A package for matching URLs in Swift.
Table of Contents
About
MyNameIsURLprovides a set of structs used to create URL-matching values. These values can be matched against URLs in a pattern context (usually as part of aswitchorif case) or manually by calling theirmatches(url:)predicate:A set of logical structs are also provided for complex matching requirements:
Installation
Swift Package Manager ⓘ
Using Xcode 11
Xcode 11 natively supports Swift Packages. To add
MyNameIsURLas a dependency:https://github.com/jemmons/MyNameIsURL.gitinto the “Search or enter package…” field and click “Next”.Using Package.swift
In your project’s
Package.swiftfile…dependencieskey in thePackageinitializer..packageentry there forMyNameIsURL, specifying the version you want:Carthage ⓘ
Ought to work. Try putting this in your
Cartfile:API
Full API documentation can be found here.
Contributing
Pull requests are welcome! Please keep in mind this is a weekend project, though, so reviews times measured in “n of weeks” is to be expected.
Found a bug? Want a feature? Issues are the way to communicate! Though the same disclaimers around response times apply. Thank you for your patience.
License
MyNameIsURLis released under the MIT license. See LICENSE for details.