4

I would like to open a url in browser but I get this error:

Use of unresolved identifier NSWorkspace

my code:

if let url = URL(string: "https://www.google.com"), NSWorkspace.shared().open(url) {
    print("default browser was successfully opened")
}
pkamb
  • 33,281
  • 23
  • 160
  • 191
S.M_Emamian
  • 17,005
  • 37
  • 135
  • 254

1 Answers1

2

You are trying to add a code for macOS coding for iOS. When coding for iOS you have to use UIApplication.shared

if let url = URL(string: "https://google.com"), UIApplication.shared.canOpenURL(url) { 
    UIApplication.shared.open(url) 
}
Leo Dabus
  • 229,809
  • 59
  • 489
  • 571