changes mainStore.subscribe(self) } func newState(state: AppState) { // when the state changes, the UI is updated to reflect the current state counterLabel.text = "\(mainStore.state.counter)" } // when either button is tapped, an action is dispatched to the store // in order to update the application state @IBAction func downTouch(_ sender: AnyObject) { mainStore.dispatch(CounterActionDecrease()) } @IBAction func upTouch(_ sender: AnyObject) { mainStore.dispatch(CounterActionIncrease()) } https://github.com/ReSwift/CounterExample ৽͍͠ঢ়ଶ "DUJPOΛඈ͚ͩ͢
// if no state has been provided, create the default state var state = state ?? AppState() switch action { case _ as CounterActionIncrease: state.counter += 1 case _ as CounterActionDecrease: state.counter -= 1 default: break } return state }
Int = 0 } /* Reducer */ struct CounterReducer: Reducer { typealias ReducerStateType = AppState func handleAction(action: Action, state: AppState?) -> AppState { // if no state has been provided, create the default state var state = state ?? AppState() switch action { case _ as CounterActionIncrease: state.counter += 1 case _ as CounterActionDecrease: state.counter -= 1 default: break } return state } }