S.M_Emamian
S.M_Emamian

Reputation: 17383

Use of unresolved identifier NSWorkspace

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

Answers (1)

Leo Dabus
Leo Dabus

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

Related Questions