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) //> 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!")
// ...
}
Xcode 11 natively supports Swift Packages. To add MyNameIsURL
as a dependency:
https://github.com/jemmons/MyNameIsURL.git
into the “Search or enter package…” field and click “Next”.In your project’s Package.swift
file…
dependencies
key in the Package
initializer..package
entry there for MyNameIsURL
, specifying the version you want:dependencies: [
.package(url: "https://github.com/jemmons/MyNameIsURL.git", from: "0.3.0")
]
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.
link |
Stars: 4 |
Last commit: 4 years ago |
Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics