Trying to make an app launch the default browser to a URL, but only if the URL entered is valid, otherwise it displays a message saying the URL is invalid.
How would
In some cases it can be enough to check that the url satisfies RFC 1808. There are several ways to do this. One example:
if let url = URL(string: urlString), url.host != nil {
// This is a correct url
}
This is because .host, as well as .path, .fragment and a few other methods would return nil if url doesn't conform to RFC 1808.
If you don't check, you might have this kind of messages in console log:
Task .<72> finished with error - code: -1002