Skip to content

Instantly share code, notes, and snippets.

@AhmedMenaim
Created December 13, 2021 21:04
Show Gist options
  • Save AhmedMenaim/335ec47ba790eacbbd58b2fc5252d881 to your computer and use it in GitHub Desktop.
Save AhmedMenaim/335ec47ba790eacbbd58b2fc5252d881 to your computer and use it in GitHub Desktop.
func savePdf() {
let pdfData = try? Data.init(contentsOf: URL(string: "http://www.africau.edu/images/default/sample.pdf")!)
let documentURL = (FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)).first! as URL
let pdfNameFromUrl = "TestFile-\(Int.random(in: 1..<10000)).pdf"
let actualPath = documentURL.appendingPathComponent(pdfNameFromUrl)
do {
try pdfData?.write(to: actualPath, options: .atomic)
debugPrint(actualPath)
}
catch {
debugPrint(error.localizedDescription)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment