I'm trying to create an URL variable from a string value. I don't understand why the resulting URL is nil
I have set up a new Xcode macOS project, placed a simple button on the View, created an action for that button and implemented the following code. The resulting url is nil.
I tried the same in Swift playground and there it worked...
@IBAction func buttonClicked(_ sender: Any) {
let urlAsString = "http://www.google.de/"
let url = URL(string: urlAsString)
if url != nil {
// Do work...
}
}
urlAsString is "http://www.google.de/" but url is nil