KMAdvertisementTableViewPresenter.swift 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. //
  2. // KMAdvertisementTablePresenter.swift
  3. // KMAdvertisement
  4. //
  5. // Created by lizhe on 2022/11/28.
  6. //
  7. class KMAdvertisementTableViewPresenter: NSObject {
  8. lazy var modelData: [KMAdvertisementModel.Section] = []
  9. var view: AnyObject?
  10. fileprivate weak var delegate: KMAdvertisementTableViewPresenterDelegate?
  11. }
  12. extension KMAdvertisementTableViewPresenter: KMAdvertisementTableViewPresenterProtocol {
  13. /**
  14. 初始化presenter
  15. */
  16. func initPresenter(view:AnyObject, data: KMAdvertisementModel) {
  17. self.delegate = view as? any KMAdvertisementTableViewPresenterDelegate
  18. self.modelData.removeAll()
  19. let array = data.content
  20. for item in array {
  21. self.modelData.append(item)
  22. }
  23. self.delegate?.showData(presenter: self, data: self.modelData)
  24. }
  25. func cleanAll() {
  26. self.modelData.removeAll()
  27. self.delegate?.showData(presenter: self, data: self.modelData)
  28. }
  29. func free() {
  30. view = nil
  31. delegate = nil
  32. }
  33. }
  34. protocol KMAdvertisementTableViewPresenterDelegate: AnyObject {
  35. /**
  36. @abstract 回调,返回处理后的数据<KMBatchProcessingViewModel>类型
  37. @param presenter
  38. @param data 返回数据
  39. */
  40. func showData(presenter: KMAdvertisementTableViewPresenter, data: Array<KMAdvertisementModel.Section>)
  41. }
  42. protocol KMAdvertisementTableViewPresenterProtocol {
  43. /**
  44. @abstract 绑定视图与数据
  45. @param view 视图
  46. @param data 资源 <KMBatchProcessingViewModel>类型
  47. */
  48. func initPresenter(view:AnyObject, data: KMAdvertisementModel)
  49. /**
  50. @abstract 解除绑定
  51. */
  52. func free()
  53. }