Swiftpack.co - Package - jemmons/MyNameIsURL

MyNameIsURL

Swift Package Carthage compatible Documentation Tests Maintainability Test Coverage

A package for matching URLs in Swift.

Table of Contents

About

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!")
// ...
}

Installation

Swift Package Manager

Using Xcode 11

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.git into the “Search or enter package…” field and click “Next”.
  • Answer Xcode’s questions about versions and you’re off to the races.

Using Package.swift

In your project’s Package.swift file…

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

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

MyNameIsURL is released under the MIT license. See LICENSE for details.

Github

link
Stars: 5
Help us keep the lights on

Dependencies

Used By

Total: 0