0

I am new to Xcode and downloaded the last 9.2 version, I am trying to insert a link to the web in a button and is not functioning. Here is the code. link not working

override func viewDidLoad() {
    super.viewDidLoad()
    // Do any additional setup after loading the view, typically from a nib.
}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}


    @IBAction func button(_ sender: Any) {



    if let url = URL(string: "https://www.youtube.com/watch?v=UPfA3mUfvGA&t=90s") {
        UIApplication.shared.canOpenURL(url)

        UIApplication.shared.open(url, options: [:], completionHandler:nil)

    }

}

}

When you press Guorlin Premium button it takes you to a website

Now, when I press the Guorlin Premium button is not working, it does not take me to the website.

Javi
  • 41
  • 1
  • 7
  • Your last two statements are contradictory. Which is true? – tadman Dec 08 '17 at 17:55
  • 1
    Sorry, I just edited it. I mean that right now the button is not working and I want to insert a link in the button. – Javi Dec 08 '17 at 17:59
  • That makes a lot more sense. Do you think the memory warning code has anything to do with this? What did you change that might've caused it to break? – tadman Dec 08 '17 at 18:05
  • I think I didnt change anything in the memory warning code, in fact that code gave it to me XCODE by default. What does it mean, and what is my error, Ive been researching and I cannot find the answer. Can you please give me a light on this? – Javi Dec 08 '17 at 18:29

1 Answers1

0

Just press option+shift+command+k and press Ok to clean the folder and try to run it on a real device instead of the simulator.

It definitely works, I had a similar problem with a similar code and it worked for me. No change in code is needed.

Marcello B.
  • 4,177
  • 11
  • 45
  • 65