KMBatchOperation.swift 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. //
  2. // KMBatchOperation.swift
  3. // PDF Reader Pro
  4. //
  5. // Created by kdanmobile on 2023/10/31.
  6. //
  7. import Foundation
  8. @objc(KMBatchOperateProtocol)
  9. protocol KMBatchOperateProtocol: AnyObject {
  10. @objc optional func fileBeginOperate(_ file: KMBatchOperateFile, info: KMBatchBaseParameter)
  11. @objc optional func fileOperating(_ file: KMBatchOperateFile, progress: CGFloat, info: KMBatchBaseParameter)
  12. @objc optional func fileOperateSuccessed(_ file: KMBatchOperateFile, info: KMBatchBaseParameter)
  13. @objc optional func fileOperateFailed(_ file: KMBatchOperateFile, error: NSError, info: KMBatchBaseParameter)
  14. @objc optional func fileOperateCanceled(_ file: KMBatchOperateFile, info: KMBatchBaseParameter)
  15. }
  16. class KMBatchOperation: Operation{
  17. var hasCanceled: Bool = false
  18. var hasFinished: Bool = false
  19. var hasExcuting: Bool = false
  20. weak var operateFile: KMBatchOperateFile?
  21. weak var delegate: KMBatchOperateProtocol?
  22. init(file: KMBatchOperateFile) {
  23. super.init()
  24. self.operateFile = file
  25. }
  26. override var isCancelled: Bool{
  27. return self.hasCanceled
  28. }
  29. override var isFinished: Bool{
  30. return self.hasFinished
  31. }
  32. override var isExecuting: Bool{
  33. return self.hasExcuting
  34. }
  35. func errorWithMsg(_ errorMsg: String) -> NSError {
  36. var errorDict = NSMutableDictionary()
  37. errorDict[NSLocalizedDescriptionKey] = errorMsg
  38. let error = NSError(domain: "PDFReaderBatchErrorDomain", code: -1, userInfo: (errorDict as! [String : Any]))
  39. return error
  40. }
  41. }