Skip to content

Instantly share code, notes, and snippets.

@candostdagdeviren
Created December 3, 2018 12:37
Show Gist options
  • Save candostdagdeviren/9b7d7cbae7f4a71ec4db021900162316 to your computer and use it in GitHub Desktop.
Save candostdagdeviren/9b7d7cbae7f4a71ec4db021900162316 to your computer and use it in GitHub Desktop.
Swift Post Testability Example Code
class FileOpener {
let urlOpener: URLOpening
init(urlOpener: URLOpening = UIApplication.shared) {
self.urlOpener = urlOpener
}
func open(identifier: String) {
guard let url = URL(string: "iosappscheme://open?id=\(identifier)") else {
debugPrint("Failed to load URL")
return
}
if urlOpener.canOpenURL(url) {
urlOpener.open(url, options: [:], completionHandler: nil)
} else {
debugPrint("Failed to open URL")
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment