ViewModelWithLocalState
public protocol ViewModelWithLocalState : ViewModelWithState
A special case of ViewModel
used to select part of the Katana app state and ViewControllerWithLocalState
‘s LocalState
that is of interest for the View.
struct CounterState: State {
var counter: Int = 0
}
struct ScreenLocalState: LocalState {
var isCounting: Bool = false
}
struct CounterViewModel: ViewModelWithState {
var countDescription: String
init(state: CounterState?, localState: ScreenLocalState) {
if let state = state, localState.isCounting {
self.countDescription = "the counter is at \(state.counter)"
} else {
self.countDescription = "we are not counting yet"
}
}
}
-
Undocumented
Declaration
Swift
associatedtype SS where Self.S == Self.SS
-
Undocumented
Declaration
Swift
associatedtype LS : LocalState
-
Instantiate a ViewModelWithLocalState given the Katana app state and the
LocalState
. -
init(state:
Extension method) Do not use this, use the
ViewModelWithLocalState.init(state:localState:)
instead.Declaration
Swift
public init?(state _: SS)