URLParser

public class URLParser : CustomStringConvertible

Splits and parses URLs into components - scheme, host, port, path, query string etc. according to the following format:

scheme:[//[user:password@]host[:port]][/]path[?query][#fragment]

Usage Example:

 // Initialize a new URLParser instance, and check whether or not a connection has been established.
 let url = "http://user:password@sample.host.com:8080/a/b/c?query=somestring#hash".data(using: .utf8)!
 let urlParser = URLParser(url: url, isConnect: false)
  • The schema of the URL.

    Declaration

    Swift

    public var schema: String?
  • The host component of the URL.

    Declaration

    Swift

    public var host: String?
  • Path portion of the URL.

    Declaration

    Swift

    public var path: String?
  • The query component of the URL.

    Declaration

    Swift

    public var query: String?
  • An optional fragment identifier providing direction to a secondary resource.

    Declaration

    Swift

    public var fragment: String?
  • The userid and password if specified in the URL.

    Declaration

    Swift

    public var userinfo: String?
  • The port specified, if any, in the URL.

    Declaration

    Swift

    public var port: UInt16?
  • The value of the query component of the URL name/value pair, for the passed in query name.

    Usage Example:

    let parsedURLParameters = urlParser.queryParameters["query"]
    

    Declaration

    Swift

    public var queryParameters: [String : String]
  • Nicely formatted description of the parsed result.

    Usage Example:

    let parsedURLDescription = urlParser.description
    

    Declaration

    Swift

    public var description: String { get }
  • Initialize a new URLParser instance.

    Usage Example:

    let parsedURL = URLParser(url: someURL, isConnect: false)
    

    Declaration

    Swift

    public init(url: Data, isConnect: Bool)

    Parameters

    url

    The URL to be parsed.

    isConnect

    A boolean, indicating whether or not a connection has been established.