Path

public struct Path : URLMatchable

Type that matches a URL based on comparison with either the URL’s path or pathComponetns propery, depending on the initializer used.

Usage:

let url = URL(string: "http://example.com/foo/bar")!
Path("/foo/bar").matches(url)          //> true
Path("/foo").matches(url)              //> false

See also

PathPrefix
  • A value that matches a URL whose path property is an empty string ("").

    Usage:

    let path = URL(string: "http://example.com/foo")!
    let slash = URL(string: "http://example.com/")!
    let noPath = URL(string: "http://exmaple.com")!
    Path.missing.matches(url: path)   //> false
    Path.missing.matches(url: slash)  //> false
    Path.missing.matches(url: noPath) //> true
    

    Declaration

    Swift

    public static let missing: URLMatchable
  • Wraps the given string to create a new Path value. It matches URLs based on their path property.

    The given path should not include a trailing slash. Both “http://example.com/foo” and “http://example.com/foo/” have a path property of "/foo". Thus Path("/foo/") will never match either.

    See also

    PathPrefix

    It should not contain a trailing slash (see “Discussion”, above).

    Declaration

    Swift

    public init(_ path: String)

    Parameters

    path

    The path to match. It will be compared for equality against URL’s path property.

  • Predicate that determines whether a Path matches a given URL.

    Declaration

    Swift

    public func matches(url: URL) -> Bool

    Parameters

    url

    The URL to be matched.

    Return Value

    true if the wrapped path is equivalent to url.path. Otherwise, false.