Not able to Create URL in Swift 5

let urlString = "www.google.com"
let url = URL(string: urlString)

It always gives nill instead of URL.

Creared New Project.

Swift 5

Xcode : 11.4.1

Replies

How have you checked it is nil ?

let urlString = "www.google.com"
let url = URL(string: urlString)
print(url)

I get

Optional(www.google.com)


Xcode has some bug that shows nil in the debug area for some structs even when it is not nil. Please do not rely on it.