Aug 25, 2017 · 1 min read
Great article! But one thing that we can think of is that enums can have computed properties, so instead of storing self.cells = loaded.cells ( in the last enum example, inside the didSet), we can make a computed property in the State enum, and either return the loaded cells, or an empty array. This way you only keep the state in one place. In the example, what happens is that you didn't clear the self.cells in the other cases. Using computed properties you can still have a finite number of states, and a clear picture for each value in every state.
var cells: [Cells] {
guard case let .loaded(cells)= self else { return [] }
return cells
}
