// // KMSignatureManager.swift // PDF Reader Pro // // Created by lizhe on 2023/10/9. // import Foundation @objcMembers class KMSignatureManager: NSObject { var signatureList: [KMSignature] = [] var filePath: String = "" override init() { signatureList = [] if let fileDirectory = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first { let fileName = "LyncPDFEditorSignatureList" let newFilePath = fileDirectory.appendingPathComponent(fileName) filePath = newFilePath.path } } @objc func loadAllSignatureList() { signatureList.removeAll() if FileManager.default.fileExists(atPath: filePath) { if let array = NSKeyedUnarchiver.unarchiveObject(withFile: filePath) as? [KMSignature] { 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 filePath.isEmpty == false { NSKeyedArchiver.archiveRootObject(signatureList, toFile: filePath) } } }