Sample project of iOS
- Using MVVM:
- With
Wireframe
for navigating from / to a screen - With
Service
for all request used in a screen
-
Using
Bond
for Binding (https://github.com/DeclarativeHub/Bond) -
Supported by API of MathJS (https://api.mathjs.org)
- 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()
}
}
- 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 = ""
}
- One-Way Binding
result
in ViewModel change resultLabel
in View:
// in View
viewModel.model.result.bind(to: resultLabel)
- 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()
}
- Using
Quick-Nimble
(https://github.com/Quick/Nimble) - Using
OHTTPStubs
(https://github.com/AliSoftware/OHHTTPStubs) - Unit Test showcase