A package for matching URLs in Swift.
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) //> trueA 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!")
// ...
}Swift Package Manager ⓘ
Xcode 11 natively supports Swift Packages. To add MyNameIsURL as a dependency:
- Open the package selection sheet (File → Swift Packages → Add Package Dependency…)
- Paste
https://github.com/jemmons/MyNameIsURL.gitinto the “Search or enter package…” field and click “Next”. - Answer Xcode’s questions about versions and you’re off to the races.
In your project’s Package.swift file…
- Find or add a
dependencieskey in thePackageinitializer. - Add a
.packageentry there forMyNameIsURL, specifying the version you want:
dependencies: [
.package(url: "https://github.com/jemmons/MyNameIsURL.git", from: "0.3.0")
]Carthage ⓘ
Ought to work. Try putting this in your Cartfile:
github "jemmons/MyNameIsURL" ~> 0.3.0
Full API documentation can be found here.
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.
MyNameIsURL is released under the MIT license. See LICENSE for details.