Guest User

Untitled

a guest
Mar 17th, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.22 KB | None | 0 0
  1. //
  2. // InstallManager.swift
  3. // OSFramework
  4. //
  5. // Created by Daniel Vela on 22/01/2018.
  6. // Copyright © 2018 Daniel Vela. All rights reserved.
  7. //
  8.  
  9. import Foundation
  10.  
  11. /// This class manages the installation of files from a bundle
  12.  
  13. public class InstallManager {
  14. public init() {
  15. }
  16.  
  17. public func destinationFileURL(_ fileName: String) -> URL {
  18. return getDocumentsDirectory().appendingPathComponent(fileName)
  19. }
  20.  
  21. public func getDocumentsDirectory() -> URL {
  22. let paths = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)
  23. return paths[0]
  24. }
  25.  
  26. public func saveFileToDocumentsDirectory(fileName: String) {
  27. let toUrl = destinationFileURL(fileName)
  28. guard let fromUrl = Bundle.main.url(forResource: fileName, withExtension: nil) else {
  29. NSLog("File %@ doesn't exists", fileName)
  30. return
  31. }
  32. let fm = FileManager()
  33. try? fm.copyItem(at: fromUrl, to: toUrl)
  34. }
  35. // if let image = UIImage(named: "example.png") {
  36. // if let data = UIImageJPEGRepresentation(image, 0.8) {
  37. // let filename = getDocumentsDirectory().appendingPathComponent("copy.png")
  38. // try? data.write(to: filename)
  39. // }
  40. // }
  41. }
Add Comment
Please, Sign In to add comment