init(_:strategy:)
Creates a URL instance by parsing the provided input in accordance with a parse strategy.
Declaration
init<T>(_ value: T.ParseInput, strategy: T) throws where T : ParseStrategy, T.ParseOutput == URLParameters
- value:
The value to parse, as the input type accepted by
strategy. For Parsestrategy, this is String. - strategy:
A parse strategy to apply when parsing
value.
Discussion
The following example parses a URL string, with a custom strategy that provides a default value for the port component if the source string doesn’t specify one.
let urlString = "https://internal.example.com/path/to/endpoint?key=value"
let url = try? URL(urlString, strategy: .url
.port(.defaultValue(8080))) // https://internal.example.com:8080/path/to/endpoint?key=value