init(string:)
Creates a URL instance from the provided string.
Declaration
init?(string: String)Parameters
- string:
A URL location.
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.