123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- //
- // KMSignatureManager.swift
- // PDF Reader Pro
- //
- // Created by lizhe on 2023/10/9.
- //
- import Foundation
- @objcMembers class KMSignatureManager: NSObject {
- var signatureList: [KMSignature] = []
- override init() {
- signatureList = []
- }
- @objc func loadAllSignatureList() {
- signatureList.removeAll()
- if let fileDirectory = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first {
- let newFilePath = fileDirectory.appendingPathComponent("NewSignatureList")
- if FileManager.default.fileExists(atPath: newFilePath.path) {
- // 使用 New 的数据
- } else { // 第一次加载 或 未存 New 的数据
- let filePath = fileDirectory.appendingPathComponent("SignatureList")
- if FileManager.default.fileExists(atPath: filePath.path) {
- NSKeyedUnarchiver.setClass(KMSignature.self, forClassName: "KMSignature")
- if let array = NSKeyedUnarchiver.unarchiveObject(withFile: filePath.path) as? [KMSignature] {
- // signatureList = array
- for model in array {
- signatureList.append(model)
- }
- }
- }
- }
- }
-
- if let fileDirectory = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first {
- let filePath = fileDirectory.appendingPathComponent("NewSignatureList")
- if FileManager.default.fileExists(atPath: filePath.path) {
- // NSKeyedUnarchiver.setClass(KMSignature.self, forClassName: "KMSignature")
- if let array = NSKeyedUnarchiver.unarchiveObject(withFile: filePath.path) as? [KMSignature] {
- // signatureList = array
- for model in array {
- signatureList.append(model)
- }
- }
- }
- }
- }
-
- func removeAllObject() {
- signatureList.removeAll()
- }
-
- func removeObject(index: Int) {
- signatureList.remove(at: index)
- }
- @objc func addSignature(_ signature: KMSignature) {
- signatureList.append(signature)
- }
- @objc func saveSingaturesToFile() {
- if let fileDirectory = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first {
- let filePath = fileDirectory.appendingPathComponent("NewSignatureList")
- NSKeyedArchiver.archiveRootObject(signatureList, toFile: filePath.path)
- }
- }
- }
|