init(string:relativeTo:)
Creates a URL instance from the provided string, relative to another URL.
Declaration
init?(string: String, relativeTo url: URL?)Parameters
- string:
A relative URL location.
- url:
A URL that provides a base location that the string extends.
Discussion
This initializer returns nil if the string doesn’t represent a valid URL even after encoding invalid characters. To check if a URL string is strictly valid according to the RFC, use the new init(string:encodingInvalidCharacters:) initializer and pass encodingInvalidCharacters: false. This leaves all characters as they are and returns nil if the URL string is explicitly invalid.