Structures

The following structures are available globally.

  • And

    Type that matches a URL based on evaluation of its wrapped URLMatchables, logically AND’d together.

    Usage:

    let url = URL(string: "https://example.com/foo")!
    And(Scheme.https, Host("example.com")).matches(url) //> true
    And(Scheme.https, Path("/foo")).matches(url)        //> true
    And(Scheme.https, Path("/not-here")).matches(url)   //> false
    
    See more

    Declaration

    Swift

    public struct And : URLMatchable
  • Type that matches a URL based on comparison with the URL’s host propery.

    Usage:

    let url = URL(string: "https://example.com")!
    Host("example.com").matches(url)      //> true
    Host(".com").matches(url)             //> false
    

    See also

    HostSuffix
    See more

    Declaration

    Swift

    public struct Host : URLMatchable
  • Type that matches a URL based on the suffix of the URL’s host propery.

    Usage:

    let url = URL(string: "https://example.com")!
    HostSuffix(["example", "com"]).matches(url) //> true
    HostSuffix(["com"]).matches(url)            //> true
    

    See also

    Host
    See more

    Declaration

    Swift

    public struct HostSuffix : URLMatchable
  • Not

    A wrapper for a URLMatchable that matches a URL whenever its wrapped value does not.

    Usage:

    let url = URL(string: "http://example.com")!
    Not(Host("example.com")).matches(url) //> false
    Not(Scheme.mailto).matches(url) //> true
    
    See more

    Declaration

    Swift

    public struct Not : URLMatchable
  • Or

    Type that matchies a URL based on evaluation of its wrapped URLMatchables, logically OR’d together.

    Usage:

    let url = URL(string: "https://example.com/foo")!
    Or(Path("/foo"), Path("/bar")).matches(url)      //> true
    Or(Scheme.http, Scheme.https).matches(url)       //> true
    Or(Host("none.test"), Path("/foo")).matches(url) //> true
    Or(Scheme.http, Path("/not-here")).matches(url)  //> false
    
    See more

    Declaration

    Swift

    public struct Or : URLMatchable
  • Type that matches a URL based on comparison with the URL’s password propery.

    Usage:

    let url = URL(string: "https://user:pass@example.com")!
    Password("pass").matches(url) //> true
    

    Note

    RFC 1738 makes a distinction between empty ("") passwords and no (nil) passwords. In the uncommon case you need to match a URL with an empty password (i.e.http://foo:@example.com”), create a Password with an empty string: Password(""). The much more common no password can be matched with Password.missing.

    See more

    Declaration

    Swift

    public struct Password : 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
    See more

    Declaration

    Swift

    public struct Path : URLMatchable
  • Type that matches a URL based on the prefix of the URL’s pathComponents property.

    Usage:

    let url = URL(string: "http://example.com/foo/bar")!
    PathPrefix(["/", "foo", "bar"]).matches(url)     //> true
    PathPrefix(["/", .wildcard, "bar"]).matches(url) //> true
    PathPrefix(["/", "foo"]).matches(url)            //> true
    

    See also

    Path
    See more

    Declaration

    Swift

    public struct PathPrefix : URLMatchable
  • Type that matches a URL based on comparison with the URL’s port propery.

    Usage:

    let url = URL(string: "https://example.com:8080")!
    Port(8080).matches(url) //> true
    
    See more

    Declaration

    Swift

    public struct Port : URLMatchable
  • Type that wraps a validated URL scheme, as per RFC 3986, §3.1.

    The value property of a Scheme should be considered safe for use in contexts which require a valid scheme name, as any invalid scheme formulations would be rejected by the contructor.

    See more

    Declaration

    Swift

    public struct Scheme : Equatable
  • Type that matches a URL based on comparison with the URL’s user propery.

    Usage:

    let url = URL(string: "https://user:pass@example.com")!
    User("user").matches(url) //> true
    

    Note

    RFC 1738 makes a distinction between empty ("") users and no (nil) users. In the uncommon case you need to match a URL with an empty user name (i.e. “http://@example.com”), create a User with an empty string: User(""). The much more common no user can be matched with User.missing.

    See more

    Declaration

    Swift

    public struct User : URLMatchable
  • Type that wraps a validated domain name (as per RFCs 952 and 1123)

    The name of a Domain value should be considered safe for use in contexts which require a valid domain name, as any invalid domain formulations would be rejected by the contructor.

    See more

    Declaration

    Swift

    public struct Domain