SHARE
TWEET

Untitled

a guest Apr 25th, 2019 63 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. func copyfileToDocumentDirectory() {
  2.         let fileName = "Test01"
  3.         let fileType = "jpg"
  4.         let copyfileName = fileName
  5.         let copyfileType = fileType
  6.         guard let bundlePath = Bundle.main.path(forResource: fileName, ofType: fileType),
  7.             let documentPath = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true).first,
  8.             let fullDocumentPath = NSURL(fileURLWithPath: documentPath).appendingPathComponent("\(copyfileName).\(copyfileType)")
  9.             else { return }
  10.        
  11.         let fileManager = FileManager.default
  12.         let fullDocumentPathString = fullDocumentPath.path
  13.         if fileManager.fileExists(atPath: fullDocumentPathString) {
  14.             print("The file exists and can not be copied.")
  15.         } else {
  16.             do {
  17.                 try fileManager.copyItem(atPath: bundlePath, toPath: fullDocumentPathString)
  18.                 print("Copied")
  19.             } catch {
  20.                 print(error)
  21.             }
  22.         }
  23.     }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top