0

Looking to open a link via UIApplication.shared.open in Swift4, Xcode9, I'm trying to use a completion block as is standard now, the most common stackoverflow answer is:

       UIApplication.shared.open(url, options: [:],
       completionHandler: {
           (success) in
              print("returned")
       })
General Grievance
  • 4,555
  • 31
  • 31
  • 45
lando2319
  • 1,509
  • 1
  • 19
  • 27

1 Answers1

4

You don't have to return any value and your code should work as it is. You just need to check if the browser was launched or not as follow:

let url = URL(string: "https://www.google.com")!

UIApplication.shared.open(url) { success in
    if success {
        print("browser successfuly opened")
    }
}
Leo Dabus
  • 229,809
  • 59
  • 489
  • 571