ArchieveUtil.swift 745 B

123456789101112131415161718192021222324252627
  1. //
  2. // ArchieveUtil.swift
  3. // CommonUtil
  4. //
  5. // Created by lijunjie on 15/12/4.
  6. // Copyright © 2015年 lijunjie. All rights reserved.
  7. //
  8. import Foundation
  9. public class ArchieveUtil {
  10. static let share = ArchieveUtil()
  11. private init () {}
  12. public func archieveObject(anObject: NSCoding, toPath: String) -> Bool {
  13. let archieveData = NSKeyedArchiver.archivedData(withRootObject: anObject)
  14. return SharedFileUtil.writeFileData(data: archieveData as NSData, toPath: toPath)
  15. }
  16. public func unarchieveFromPath(filePath: String) -> AnyObject? {
  17. return NSKeyedUnarchiver.unarchiveObject(withFile: filePath) as AnyObject?
  18. }
  19. }
  20. public let SharedArchieveUtil: ArchieveUtil = ArchieveUtil.share