Host

public struct Host : 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
  • A value that matches a URL with a host property of nil.

    Usage:

    let host = URL(string: "http://example.com")!
    let noHost = URL(string: "http://")!
    Host.missing.matches(url: host)   //> false
    Host.missing.matches(url: noHost) //> true
    

    Declaration

    Swift

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

    See also

    HostSuffix

    Declaration

    Swift

    public init(_ host: String)

    Parameters

    host

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

  • Predicate that determines whether a Host 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 host is equivalent to url.host. Otherwise, false.