- Create empty
MainFeature.swift
file inside exmpl/Main
folder in exmpl
project
- Add imports
import Foundation
import Highway
- Add namespace for your module
// ...
enum MainFeature {}
- Add state data
// ...
extension MainFeature {
struct State: Equatable {
var count = 0
}
}
- Add actions/events
// ...
extension MainFeature {
enum Action: Equatable {
case increment
case decrement
}
}
- Add reducer and business logic for state mutation
// ...
extension MainFeature {
static func reducer() -> Reducer<MainFeature.State, MainFeature.Action> {
return .init { state, action in
switch action {
case .increment:
var state = state
state.count += 1
return state
case .decrement:
var state = state
state.count -= 1
return state
}
}
}
}
Next: View