Reputation: 17383
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")
}
Upvotes: 4
Views: 2060
Reputation: 236315
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)
}
Upvotes: 2