JCFileManager.swift 763 B

123456789101112131415161718192021222324252627282930
  1. //
  2. // JCFileManager.swift
  3. // JChat
  4. //
  5. // Created by deng on 2017/7/24.
  6. // Copyright © 2017年 HXHG. All rights reserved.
  7. //
  8. import UIKit
  9. class JCFileManager: NSObject {
  10. static func fileExists(atPath: String) -> Bool {
  11. let fileManager = FileManager.default
  12. return fileManager.fileExists(atPath: atPath)
  13. }
  14. static func saveFileToLocal(data: Data, savaPath: String) -> Bool {
  15. let fileManager = FileManager.default
  16. let exist = fileManager.fileExists(atPath: savaPath)
  17. if exist {
  18. try! fileManager.removeItem(atPath: savaPath)
  19. }
  20. if !fileManager.createFile(atPath: savaPath, contents: data, attributes: nil) {
  21. return false
  22. }
  23. return true
  24. }
  25. }