Skip to content
master
Go to file
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.

README.md

Auto Calculate Math Statement

Sample project of iOS

  1. Using MVVM:
  • With Wireframe for navigating from / to a screen
  • With Service for all request used in a screen

  1. Using Bond for Binding (https://github.com/DeclarativeHub/Bond)

  2. Supported by API of MathJS (https://api.mathjs.org)


Current project is using One-Way and Two-Ways Binding, binding placed in View:

  1. Main binding
// in View
func setupBinding() {
    textField.reactive.text.bidirectionalBind(to: viewModel.model.statement)
    viewModel.model.result.bind(to: resultLabel)
    viewModel.showLoading.bind(to: self) { vc, _ in
        vc.showLoading()
    }
    viewModel.hideLoading.bind(to: self) { vc, _ in
        vc.hideLoading()
    }
}
  1. Two-Ways Binding

Everytime user typing in the textField in "View", the value of statement in "ViewModel" also changed.

// in View
textField.reactive.text.bidirectionalBind(to: viewModel.model.statement)

And then, when user click the button "CLEAR", it trigger function reset() in "ViewModel". This function clear the statement in "ViewModel", and also change the textField in "View".

// in View
@IBAction func onTapClearButton(_ sender: Any) {
    viewModel.reset()
}
// in ViewModel
func reset() {
    model.statement.value = ""
    model.result.value = ""
}
  1. One-Way Binding

result in ViewModel change resultLabel in View:

// in View
viewModel.model.result.bind(to: resultLabel)
  1. Example of using signal to trigger loading in "View" from "ViewModel"
// in View
viewModel.showLoading.bind(to: self) { vc, _ in
    vc.showLoading()
}
viewModel.hideLoading.bind(to: self) { vc, _ in
    vc.hideLoading()
}

Contain Unit Tests:

Demo:


Special thanks to OVO-iOS-Team

About

Sample project iOS with MVVM (Binding using Bond) + Unit Test (using Quick-Nimble and OHTTPStubs), to auto calculate math statement

Topics

Resources

Releases

No releases published

Packages

No packages published
You can’t perform that action at this time.