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
whosepath
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 matchesURL
s based on theirpath
property.The given
path
should not include a trailing slash. Both “http://example.com/foo” and “http://example.com/foo/” have apath
property of"/foo"
. ThusPath("/foo/")
will never match either.See also
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
’spath
property. -
Predicate that determines whether a
Path
matches a givenURL
.Declaration
Swift
public func matches(url: URL) -> Bool
Parameters
url
The
URL
to be matched.Return Value
true
if the wrapped path is equivalent tourl.path
. Otherwise,false
.