Skip to content

Instantly share code, notes, and snippets.

@colinhumber
colinhumber / step.swift
Last active April 4, 2019 22:17
Recursive Wizard Step
typealias SomeContent = String
indirect enum Step {
case step1(SomeContent, Step?)
case step2(SomeContent, Step?)
case step3(SomeContent, Step?)
}
let step1 = Step.step1("Step 1 data", nil)
let step2 = Step.step2("Step 2 data", step1)
// works fine, but receiveValue may return on different threads
viewModel.$snapshot
.sink { [weak self] snapshot in
guard let self = self else { return }
var animateDifferences = false
switch self.viewModel.state {
case .idle, .empty, .loading, .searching:
animateDifferences = false
[
{
"iso2": "AF",
"translations": {
"br": "Afeganistão",
"nl": "Afghanistan",
"hr": "Afganistan",
"ja": "アフガニスタン",
"fr": "Afghanistan",
"it": "Afghanistan",