Created
July 16, 2019 16:41
-
-
Save shanecowherd/57fc313e11497e24b4186fcee4e30c85 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//https://developer.apple.com/documentation/foundation/urlsession/1411511-downloadtask | |
let url = URL(string: "https://www.shanecowherd.com")! | |
let downloadTask = URLSession.shared.downloadTask(with: url) { (downloadedFile, response, error) in | |
// Make sure the temporary file exists and you have access to it | |
guard let downloadedFile = downloadedFile, FileManager.default.fileExists(atPath: downloadedFile.path) else { | |
return | |
} | |
//downloadedFile - The location of a temporary file where the server’s response is stored. You must move this file or open it for reading before your completion handler returns. Otherwise, the file is deleted, and the data is lost. | |
let fileData = try? Data(contentsOf: downloadedFile) | |
let fileString = String(data: fileData, encoding: .utf8) | |
} | |
downloadTask.resume() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment