Swift URL Missing argument label ‘string:’ in call

The error “Missing argument label ‘string:’ in call” is caused when you try to create a URL object in Swift without specifying the argument label for the string parameter.

Solution for Missing argument label ‘string:’ in call in URL call is to replace

let url = URL(yourStringUrl)

it to

URL(string: yourStringUrl)

Above, string: is the argument label for your string parameter in URL call. yourStringUrl could be “https://foo.com”

Example:

let url = URL(string: "https://foo.com")

When you create a URL object, it’s important to make sure that the string you pass in is actually a valid URL. You can do this by using the URL(string:) initializer. If the string is not a valid URL, the initializer will return nil. It can be tested like this:

if let url = URL(string: "https://foo.com") {
   // Play with the url object
} else {
   // Handle the error in your application
}