KMSignatureManager.swift 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. //
  2. // KMSignatureManager.swift
  3. // PDF Reader Pro
  4. //
  5. // Created by lizhe on 2023/10/9.
  6. //
  7. import Foundation
  8. @objcMembers class KMSignatureManager: NSObject {
  9. var signatureList: [KMSignature] = []
  10. var filePath: String = ""
  11. override init() {
  12. signatureList = []
  13. if let fileDirectory = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first {
  14. let fileName = "LyncPDFEditorSignatureList"
  15. let newFilePath = fileDirectory.appendingPathComponent(fileName)
  16. filePath = newFilePath.path
  17. }
  18. }
  19. @objc func loadAllSignatureList() {
  20. signatureList.removeAll()
  21. if FileManager.default.fileExists(atPath: filePath) {
  22. if let array = NSKeyedUnarchiver.unarchiveObject(withFile: filePath) as? [KMSignature] {
  23. for model in array {
  24. signatureList.append(model)
  25. }
  26. }
  27. }
  28. }
  29. func removeAllObject() {
  30. signatureList.removeAll()
  31. }
  32. func removeObject(index: Int) {
  33. signatureList.remove(at: index)
  34. }
  35. @objc func addSignature(_ signature: KMSignature) {
  36. signatureList.append(signature)
  37. }
  38. @objc func saveSingaturesToFile() {
  39. if filePath.isEmpty == false {
  40. NSKeyedArchiver.archiveRootObject(signatureList, toFile: filePath)
  41. }
  42. }
  43. }