I am currently opening the link in my app in a WebView, but I\'m looking for an option to open the link in Safari instead.
Swift 3 & IOS 10.2
UIApplication.shared.open(URL(string: "http://www.stackoverflow.com")!, options: [:], completionHandler: nil)
Swift 3 & IOS 10.2
In Swift 2.0:
UIApplication.sharedApplication().openURL(NSURL(string: "http://stackoverflow.com")!)
Swift 5
if let url = URL(string: "https://www.google.com") {
UIApplication.shared.open(url)
}
It's not "baked in to Swift", but you can use standard UIKit methods to do it. Take a look at UIApplication's openUrl(_:) (deprecated) and open(_:options:completionHandler:).
Swift 4 + Swift 5 (iOS 10 and above)
guard let url = URL(string: "https://stackoverflow.com") else { return }
UIApplication.shared.open(url)
Swift 3 (iOS 9 and below)
guard let url = URL(string: "https://stackoverflow.com") else { return }
UIApplication.shared.openURL(url)
Swift 2.2
guard let url = URL(string: "https://stackoverflow.com") else { return }
UIApplication.sharedApplication().openURL(url)