项目作者: nick6969

项目描述 :
MVVM - POP & OOP
高级语言: Swift
项目地址: git://github.com/nick6969/MVVM.git
创建时间: 2018-04-07T06:42:40Z
项目社区:https://github.com/nick6969/MVVM

开源协议:MIT License

下载


關於

這是一個 MVVM 的展示專案

ViewModel 使用 POP & OOP 建立

方便使用,並且減少大量重複的 Code

架構

Model

Just Model


ViewModel

持有 Models

  1. var models: [Model]

有自己的狀態

  1. var status: ViewModelStatus

負責取得資料(Web Api / Locale DB)

  1. func loadData()
  2. func loadDataMode()

負責通知 ViewController Loading 狀態

  1. var loadingDelegate: ViewModelLoadingDelegate?
  2. var loadingStatusDelegate: ViewModelLoadingStatusDelegate?

提供 Method 讓 ViewController 取用 Model

  1. var datasCount: Int
  2. func model(at index: Int) -> Model?
  3. func isLastData(index: Int) -> Bool
  4. func isLoadMore(index: Int) -> Bool

提供 Method 讓 ViewController 呼叫做事

  1. func refreshData()
  2. func nextStatus()

ViewController

持有 ViewModel

  1. var viewModel: BaseViewModel

conform ViewModel 的 Delegate

extension ViewController: ViewModelLoadingDelegate

  1. func loadingDone()
  2. func loadingFail(_ error: Error?)

extension ViewController: ViewModelLoadingStatusDelegate

  1. func showEmptyView(with: Error?)
  2. func removeEmptyView()
  3. func showLoading(_ bool: Bool)

請 ViewModel 做事

  1. viewModel.nextStatus()
  2. viewModel.refreshData()